Skip to content

Commit 96384b0

Browse files
committed
Merge branch '4.4'
2 parents 850ba41 + 62f6717 commit 96384b0

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

CurlHttpClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public function request(string $method, string $url, array $options = []): Respo
244244

245245
// Prevent curl from sending its default Accept and Expect headers
246246
foreach (['accept', 'expect'] as $header) {
247-
if (!isset($options['normalized_headers'][$header])) {
247+
if (!isset($options['normalized_headers'][$header][0])) {
248248
$curlopts[CURLOPT_HTTPHEADER][] = $header.':';
249249
}
250250
}
@@ -441,7 +441,7 @@ private static function createRedirectResolver(array $options, string $host): \C
441441
return 0 !== stripos($h, 'Host:');
442442
});
443443

444-
if (isset($options['normalized_headers']['authorization']) || isset($options['normalized_headers']['cookie'])) {
444+
if (isset($options['normalized_headers']['authorization'][0]) || isset($options['normalized_headers']['cookie'][0])) {
445445
$redirectHeaders['no_auth'] = array_filter($options['headers'], static function ($h) {
446446
return 0 !== stripos($h, 'Authorization:') && 0 !== stripos($h, 'Cookie:');
447447
});

HttpClientTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
5555
}
5656

5757
if (!isset($options['normalized_headers']['accept'])) {
58-
$options['normalized_headers']['accept'] = [$options['headers'][] = 'Accept: *'];
58+
$options['normalized_headers']['accept'] = [$options['headers'][] = 'Accept: */*'];
5959
}
6060

6161
if (isset($options['body'])) {

Tests/HttpClientTestCase.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,34 @@ public function testMaxDuration()
2121
$this->markTestSkipped('Implemented as of version 4.4');
2222
}
2323

24+
public function testAcceptHeader()
25+
{
26+
$client = $this->getHttpClient(__FUNCTION__);
27+
28+
$response = $client->request('GET', 'http://localhost:8057');
29+
$requestHeaders = $response->toArray();
30+
31+
$this->assertSame('*/*', $requestHeaders['HTTP_ACCEPT']);
32+
33+
$response = $client->request('GET', 'http://localhost:8057', [
34+
'headers' => [
35+
'Accept' => 'foo/bar',
36+
],
37+
]);
38+
$requestHeaders = $response->toArray();
39+
40+
$this->assertSame('foo/bar', $requestHeaders['HTTP_ACCEPT']);
41+
42+
$response = $client->request('GET', 'http://localhost:8057', [
43+
'headers' => [
44+
'Accept' => null,
45+
],
46+
]);
47+
$requestHeaders = $response->toArray();
48+
49+
$this->assertArrayNotHasKey('HTTP_ACCEPT', $requestHeaders);
50+
}
51+
2452
public function testToStream()
2553
{
2654
$client = $this->getHttpClient(__FUNCTION__);

Tests/HttpClientTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function provideRemoveDotSegments()
172172
public function testAuthBearerOption()
173173
{
174174
[, $options] = self::prepareRequest('POST', 'http://example.com', ['auth_bearer' => 'foobar'], HttpClientInterface::OPTIONS_DEFAULTS);
175-
$this->assertSame(['Accept: *', 'Authorization: Bearer foobar'], $options['headers']);
175+
$this->assertSame(['Accept: */*', 'Authorization: Bearer foobar'], $options['headers']);
176176
$this->assertSame(['Authorization: Bearer foobar'], $options['normalized_headers']['authorization']);
177177
}
178178

Tests/MockHttpClientTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
3636
"SERVER_NAME": "127.0.0.1",
3737
"REQUEST_URI": "/",
3838
"REQUEST_METHOD": "GET",
39+
"HTTP_ACCEPT": "*/*",
3940
"HTTP_FOO": "baR",
4041
"HTTP_HOST": "localhost:8057"
4142
}';
@@ -114,6 +115,12 @@ protected function getHttpClient(string $testCase): HttpClientInterface
114115
$responses[] = $mock;
115116
break;
116117

118+
case 'testAcceptHeader':
119+
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
120+
$responses[] = new MockResponse(str_replace('*/*', 'foo/bar', $body), ['response_headers' => $headers]);
121+
$responses[] = new MockResponse(str_replace('"HTTP_ACCEPT": "*/*",', '', $body), ['response_headers' => $headers]);
122+
break;
123+
117124
case 'testResolve':
118125
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
119126
$responses[] = new MockResponse($body, ['response_headers' => $headers]);

0 commit comments

Comments
 (0)