10000 [HttpClient] Fix a typo in NoPrivateNetworkHttpClient by Jontsa · Pull Request #59250 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpClient] Fix a typo in NoPrivateNetworkHttpClient #59250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[HttpClient] Fix a typo in NoPrivateNetworkHttpClient
  • Loading branch information
Jontsa committed Dec 18, 2024
commit e6ec2126c8c74b7690883a16ea7fe410eb671b6a
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
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
Loading
0