Skip to content

Commit

Permalink
Merge pull request #3109 from michalsn/clear_accept_encoding
Browse files Browse the repository at this point in the history
Remove Accept-Encoding header after using populateHeaders() method
  • Loading branch information
lonnieezell authored Jun 18, 2020
2 parents 1eac4e9 + 0719cbc commit 2f59f71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ protected function applyRequestHeaders(array $curl_options = []): array
$this->populateHeaders();
// Otherwise, it will corrupt the request
$this->removeHeader('Host');
$this->removeHeader('Accept-Encoding');
}

$headers = $this->getHeaders();
Expand Down
10 changes: 9 additions & 1 deletion tests/system/HTTP/CURLRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public function testOptionHeadersUsingPopulate()
{
$_SERVER['HTTP_HOST'] = 'site1.com';
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-US';
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate, br';

$options = [
'base_uri' => 'http://www.foo.com/api/v1/',
Expand All @@ -187,6 +188,8 @@ public function testOptionHeadersUsingPopulate()
$this->assertEquals('en-US', $request->getHeader('Accept-Language')->getValue());
// but we skip Host header - since it would corrupt the request
$this->assertNull($request->getHeader('Host'));
// and Accept-Encoding
$this->assertNull($request->getHeader('Accept-Encoding'));
}

/**
Expand All @@ -196,16 +199,21 @@ public function testOptionHeadersNotUsingPopulate()
{
$_SERVER['HTTP_HOST'] = 'site1.com';
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-US';
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate, br';

$options = [
'base_uri' => 'http://www.foo.com/api/v1/',
'headers' => ['Host' => 'www.foo.com'],
'headers' => [
'Host' => 'www.foo.com',
'Accept-Encoding' => '',
],
];
$request = $this->getRequest($options);
$request->get('example');
// if headers for the request are defined we use them
$this->assertNull($request->getHeader('Accept-Language'));
$this->assertEquals('www.foo.com', $request->getHeader('Host')->getValue());
$this->assertEquals('', $request->getHeader('Accept-Encoding')->getValue());
}

//--------------------------------------------------------------------
Expand Down

0 comments on commit 2f59f71

Please sign in to comment.