Skip to content

Commit 71ac7a9

Browse files
authored
Merge pull request #217 from phil-davis/remove-header-overwrite-with-null-6
[6.0] Remove header overwrite with null
2 parents 8deee75 + 0adca1e commit 71ac7a9

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Diff for: lib/Client.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,10 @@ protected function createCurlSettingsArray(RequestInterface $request): array
404404
$nHeaders[] = $key.': '.$value;
405405
}
406406
}
407-
$settings[CURLOPT_HTTPHEADER] = $nHeaders;
407+
408+
if ([] !== $nHeaders) {
409+
$settings[CURLOPT_HTTPHEADER] = $nHeaders;
410+
}
408411
$settings[CURLOPT_URL] = $request->getUrl();
409412
// FIXME: CURLOPT_PROTOCOLS is currently unsupported by HHVM
410413
if (defined('CURLOPT_PROTOCOLS')) {

Diff for: tests/HTTP/ClientTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@ public function testCreateCurlSettingsArrayGET(): void
3434
$this->assertEquals($settings, $client->createCurlSettingsArray($request));
3535
}
3636

37+
public function testCreateCurlSettingsHTTPHeader(): void
38+
{
39+
$client = new ClientMock();
40+
$header = [
41+
'Authorization: Bearer 12345',
42+
];
43+
$client->addCurlSetting(CURLOPT_POSTREDIR, 0);
44+
$client->addCurlSetting(CURLOPT_HTTPHEADER, $header);
45+
46+
$request = new Request('GET', 'http://example.org/');
47+
48+
$settings = [
49+
CURLOPT_RETURNTRANSFER => true,
50+
CURLOPT_HEADER => true,
51+
CURLOPT_POSTREDIR => 0,
52+
CURLOPT_HTTPHEADER => ['Authorization: Bearer 12345'],
53+
CURLOPT_NOBODY => false,
54+
CURLOPT_URL => 'http://example.org/',
55+
CURLOPT_CUSTOMREQUEST => 'GET',
56+
CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)',
57+
CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
58+
CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
59+
];
60+
61+
self::assertEquals($settings, $client->createCurlSettingsArray($request));
62+
}
63+
3764
public function testCreateCurlSettingsArrayHEAD(): void
3865
{
3966
$client = new ClientMock();

0 commit comments

Comments
 (0)