Skip to content

Commit 88898d8

Browse files
committed
[HttpClient] Fix a typo in NoPrivateNetworkHttpClient
1 parent 8057c7c commit 88898d8

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

NoPrivateNetworkHttpClient.php

+1-1
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
}

Tests/NoPrivateNetworkHttpClientTest.php

+21
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)