Skip to content

Commit 339ba21

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: reject URLs containing whitespaces Update validators.fa.xlf [HttpClient] Fix a typo in NoPrivateNetworkHttpClient
2 parents 5432299 + e221bfd commit 339ba21

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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
}

Tests/NoPrivateNetworkHttpClientTest.php

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

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

0 commit comments

Comments
 (0)