Permalink
Browse files

Merge branch 'hotfix/2962'

Close #2962
  • Loading branch information...
2 parents ca1e7b6 + 83e3218 commit 8cbf2350a02d64818c1c4f013697e711b42ce697 @weierophinney weierophinney committed Dec 10, 2012
Showing with 27 additions and 4 deletions.
  1. +3 −3 library/Zend/Http/Client.php
  2. +24 −1 tests/ZendTest/Http/ClientTest.php
@@ -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';
}
}
@@ -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
@@ -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.