Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/2962' into develop
Browse files Browse the repository at this point in the history
Forward port zendframework/zendframework#2962

Conflicts:
	tests/ZendTest/Http/ClientTest.php
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1068,11 +1068,11 @@ protected function prepareHeaders($body, $uri)

// Set the Accept-encoding header if not set - depending on whether
// zlib is available or not.
if (! isset($this->headers['accept-encoding'])) {
if (!$this->getRequest()->getHeaders()->has('Accept-Encoding')) {
if (function_exists('gzinflate')) {
$headers['Accept-encoding'] = 'gzip, deflate';
$headers['Accept-Encoding'] = 'gzip, deflate';
} else {
$headers['Accept-encoding'] = 'identity';
$headers['Accept-Encoding'] = 'identity';
}
}

Expand Down
25 changes: 24 additions & 1 deletion test/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
namespace ZendTest\Http;

use Zend\Http\Client;
use Zend\Http\Exception;

use Zend\Http\Header\AcceptEncoding;
use Zend\Http\Header\SetCookie;

class ClientTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -101,4 +102,26 @@ public function testCanOverrideArgSeparator()
$client->setArgSeparator(';');
$this->assertEquals(';', $client->getArgSeparator());
}

public function testClientUsesAcceptEncodingHeaderFromRequestObject()
{
$client = new Client();

$client->setAdapter('Zend\Http\Client\Adapter\Test');

$request = $client->getRequest();

$acceptEncodingHeader = new AcceptEncoding();
$acceptEncodingHeader->addEncoding('foo', 1);
$request->getHeaders()->addHeader($acceptEncodingHeader);

$client->send();

$rawRequest = $client->getLastRawRequest();

$this->assertNotContains('Accept-Encoding: gzip, deflate', $rawRequest, null, true);
$this->assertNotContains('Accept-Encoding: identity', $rawRequest, null, true);

$this->assertContains('Accept-Encoding: foo', $rawRequest);
}
}

0 comments on commit d398ec0

Please sign in to comment.