From 4d547e5259221bd37685f4ddc8e8947acc2cb755 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 16 Aug 2024 12:20:10 +0200 Subject: [PATCH] do not overwrite the host to request --- CurlHttpClient.php | 8 ++++---- Tests/CurlHttpClientTest.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CurlHttpClient.php b/CurlHttpClient.php index 19bd456..478f9c0 100644 --- a/CurlHttpClient.php +++ b/CurlHttpClient.php @@ -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; diff --git a/Tests/CurlHttpClientTest.php b/Tests/CurlHttpClientTest.php index 8e50d13..9ea9762 100644 --- a/Tests/CurlHttpClientTest.php +++ b/Tests/CurlHttpClientTest.php @@ -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); + } }