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

Commit

Permalink
Merge branch 'hotfix/2962'
Browse files Browse the repository at this point in the history
Close #2962
  • Loading branch information
weierophinney committed Dec 10, 2012
2 parents ca1e7b6 + 83e3218 commit 8cbf235
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
6 changes: 3 additions & 3 deletions library/Zend/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1040,11 +1040,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 tests/ZendTest/Http/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 @@ -79,4 +80,26 @@ public function testIfArrayIteratorOfHeadersCanBeSet()
$cookies = $client->getCookies();
$this->assertEquals(2, count($cookies));
}

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 8cbf235

Please sign in to comment.