8000 bug #59250 [HttpClient] Fix a typo in NoPrivateNetworkHttpClient (Jon… · symfony/symfony@c2cc75d · GitHub
[go: up one dir, main page]

Skip to content

Commit c2cc75d

Browse files
committed
bug #59250 [HttpClient] Fix a typo in NoPrivateNetworkHttpClient (Jontsa)
This PR was merged into the 6.4 branch. Discussion ---------- [HttpClient] Fix a typo in NoPrivateNetworkHttpClient | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #59244 | License | MIT Fix a typo in NoPrivateNetworkHttpClient that may cause `Undefined array key` error if server returns redirect response to a POST request. Commits ------- e6ec212 [HttpClient] Fix a typo in NoPrivateNetworkHttpClient
2 parents be52235 + e6ec212 commit c2cc75d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Symfony/Component/HttpClient/NoPrivateNetworkHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function request(string $method, string $url, array $options = []): Respo
138138
$filterContentHeaders = static function ($h) {
139139
return 0 !== stripos($h, 'Content-Length:') && 0 !== stripos($h, 'Content-Type:') && 0 !== stripos($h, 'Transfer-Encoding:');
140140
};
141-
$options['header'] = array_filter($options['header'], $filterContentHeaders);
141+
$options['headers'] = array_filter($options['headers'], $filterContentHeaders);
142142
$redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth'], $filterContentHeaders);
143143
$redirectHeaders['with_auth'] = array_filter($redirectHeaders['with_auth'], $filterContentHeaders);
144144
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,27 @@ public function testNonCallableOnProgressCallback()
173173
$client->request('GET', $url, ['on_progress' => $customCallback]);
174174
}
175175

176+
public function testHeadersArePassedOnRedirect()
177+
{
178+
$ipAddr = '104.26.14.6';
179+
$url = sprintf('http://%s/', $ipAddr);
180+
$content = 'foo';
181+
182+
$callback = function ($method, $url, $options) use ($content): MockResponse {
183+
$this->assertArrayHasKey('headers', $options);
184+
$this->assertNotContains('content-type: application/json', $options['headers']);
185+
$this->assertContains('foo: bar', $options['headers']);
186+
return new MockResponse($content);
187+
};
188+
$responses = [
189+
new MockResponse('', ['http_code' => 302, 'redirect_url' => 'http://104.26.14.7']),
190+
$callback,
191+
];
192+
$client = new NoPrivateNetworkHttpClient(new MockHttpClient($responses));
193+
$response = $client->request('POST', $url, ['headers' => ['foo' => 'bar', 'content-type' => 'application/json']]);
194+
$this->assertEquals($content, $response->getContent());
195+
}
196+
176197
private function getMockHttpClient(string $ipAddr, string $content)
177198
{
178199
return new MockHttpClient(new MockResponse($content, ['primary_ip' => $ipAddr]));

0 commit comments

Comments
 (0)
0