Skip to content

Commit

Permalink
Merge pull request #218 from phil-davis/remove-header-overwrite-with-…
Browse files Browse the repository at this point in the history
…null-5

[5.1] Remove header overwrite with null
  • Loading branch information
phil-davis authored Aug 17, 2023
2 parents b6fa04f + 9a438d0 commit 985f24a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,10 @@ protected function createCurlSettingsArray(RequestInterface $request): array
$nHeaders[] = $key.': '.$value;
}
}
$settings[CURLOPT_HTTPHEADER] = $nHeaders;

if ([] !== $nHeaders) {
$settings[CURLOPT_HTTPHEADER] = $nHeaders;
}
$settings[CURLOPT_URL] = $request->getUrl();
// FIXME: CURLOPT_PROTOCOLS is currently unsupported by HHVM
if (defined('CURLOPT_PROTOCOLS')) {
Expand Down
27 changes: 27 additions & 0 deletions tests/HTTP/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,33 @@ public function testCreateCurlSettingsArrayGET()
$this->assertEquals($settings, $client->createCurlSettingsArray($request));
}

public function testCreateCurlSettingsHTTPHeader(): void
{
$client = new ClientMock();
$header = [
'Authorization: Bearer 12345',
];
$client->addCurlSetting(CURLOPT_POSTREDIR, 0);
$client->addCurlSetting(CURLOPT_HTTPHEADER, $header);

$request = new Request('GET', 'http://example.org/');

$settings = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_POSTREDIR => 0,
CURLOPT_HTTPHEADER => ['Authorization: Bearer 12345'],
CURLOPT_NOBODY => false,
CURLOPT_URL => 'http://example.org/',
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)',
CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
];

self::assertEquals($settings, $client->createCurlSettingsArray($request));
}

public function testCreateCurlSettingsArrayHEAD()
{
$client = new ClientMock();
Expand Down

0 comments on commit 985f24a

Please sign in to comment.