Skip to content

Commit

Permalink
Merge branch '6.4' into 7.1
Browse files Browse the repository at this point in the history
* 6.4:
  reject URLs containing whitespaces
  Update validators.fa.xlf
  [HttpClient] Fix a typo in NoPrivateNetworkHttpClient
  • Loading branch information
fabpot committed Dec 30, 2024
2 parents 817b619 + 88898d8 commit e221bfd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NoPrivateNetworkHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function request(string $method, string $url, array $options = []): Respo
$filterContentHeaders = static function ($h) {
return 0 !== stripos($h, 'Content-Length:') && 0 !== stripos($h, 'Content-Type:') && 0 !== stripos($h, 'Transfer-Encoding:');
};
$options['header'] = array_filter($options['header'], $filterContentHeaders);
$options['headers'] = array_filter($options['headers'], $filterContentHeaders);
$redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth'], $filterContentHeaders);
$redirectHeaders['with_auth'] = array_filter($redirectHeaders['with_auth'], $filterContentHeaders);
}
Expand Down
21 changes: 21 additions & 0 deletions Tests/NoPrivateNetworkHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,27 @@ public function testNonCallableOnProgressCallback()
$client->request('GET', $url, ['on_progress' => $customCallback]);
}

public function testHeadersArePassedOnRedirect()
{
$ipAddr = '104.26.14.6';
$url = sprintf('http://%s/', $ipAddr);
$content = 'foo';

$callback = function ($method, $url, $options) use ($content): MockResponse {
$this->assertArrayHasKey('headers', $options);
$this->assertNotContains('content-type: application/json', $options['headers']);
$this->assertContains('foo: bar', $options['headers']);
return new MockResponse($content);
};
$responses = [
new MockResponse('', ['http_code' => 302, 'redirect_url' => 'http://104.26.14.7']),
$callback,
];
$client = new NoPrivateNetworkHttpClient(new MockHttpClient($responses));
$response = $client->request('POST', $url, ['headers' => ['foo' => 'bar', 'content-type' => 'application/json']]);
$this->assertEquals($content, $response->getContent());
}

private function getMockHttpClient(string $ipAddr, string $content)
{
return new MockHttpClient(new MockResponse($content, ['primary_ip' => $ipAddr]));
Expand Down

0 comments on commit e221bfd

Please # to comment.