Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5017efa

Browse files
committed
do not overwrite the host to request
1 parent ca84bcc commit 5017efa

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/Symfony/Component/HttpClient/CurlHttpClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ public function request(string $method, string $url, array $options = []): Respo
185185
$multi->reset();
186186
}
187187

188-
foreach ($options['resolve'] as $host => $ip) {
189-
$resolve[] = null === $ip ? "-$host:$port" : "$host:$port:$ip";
190-
$multi->dnsCache->hostnames[$host] = $ip;
191-
$multi->dnsCache->removals["-$host:$port"] = "-$host:$port";
188+
foreach ($options['resolve'] as $resolveHost => $ip) {
189+
$resolve[] = null === $ip ? "-$resolveHost:$port" : "$resolveHost:$port:$ip";
190+
$multi->dnsCache->hostnames[$resolveHost] = $ip;
191+
$multi->dnsCache->removals["-$resolveHost:$port"] = "-$resolveHost:$port";
192192
}
193193

194194
$curlopts[\CURLOPT_RESOLVE] = $resolve;

src/Symfony/Component/HttpClient/Tests/CurlHttpClientTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,20 @@ public function testOverridingInternalAttributesUsingCurlOptions()
128128
],
129129
]);
130130
}
131+
132+
public function testKeepAuthorizationHeaderOnRedirectToSameHostWithConfiguredHostToIpAddressMapping()
133+
{
134+
$httpClient = $this->getHttpClient(__FUNCTION__);
135+
$response = $httpClient->request('POST', 'http://127.0.0.1:8057/301', [
136+
'headers' => [
137+
'Authorization' => 'Basic Zm9vOmJhcg==',
138+
],
139+
'resolve' => [
140+
'symfony.com' => '10.10.10.10',
141+
],
142+
]);
143+
144+
$this->assertSame(200, $response->getStatusCode());
145+
$this->assertSame('/302', $response->toArray()['REQUEST_URI'] ?? null);
146+
}
131147
}

0 commit comments

Comments
 (0)