Skip to content

Commit

Permalink
do not overwrite the host to request
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Aug 20, 2024
1 parent 6ad5e27 commit 4d547e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ public function request(string $method, string $url, array $options = []): Respo
$multi->reset();
}

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

$curlopts[\CURLOPT_RESOLVE] = $resolve;
Expand Down
16 changes: 16 additions & 0 deletions Tests/CurlHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,20 @@ public function testOverridingInternalAttributesUsingCurlOptions()
],
]);
}

public function testKeepAuthorizationHeaderOnRedirectToSameHostWithConfiguredHostToIpAddressMapping()
{
$httpClient = $this->getHttpClient(__FUNCTION__);
$response = $httpClient->request('POST', 'http://127.0.0.1:8057/301', [
'headers' => [
'Authorization' => 'Basic Zm9vOmJhcg==',
],
'resolve' => [
'symfony.com' => '10.10.10.10',
],
]);

$this->assertSame(200, $response->getStatusCode());
$this->assertSame('/302', $response->toArray()['REQUEST_URI'] ?? null);
}
}

0 comments on commit 4d547e5

Please sign in to comment.