Allow Accept-Encoding header to be set explicitly by http request #2962

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+27 −5
Split
@@ -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,8 +11,8 @@
namespace ZendTest\Http;
use Zend\Http\Client;
-use Zend\Http\Exception;
-use Zend\Http\Header\SetCookie;
+
+use Zend\Http\Header\AcceptEncoding;
class ClientTest extends \PHPUnit_Framework_TestCase
{
@@ -79,4 +79,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);
+ }
}