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

Commit dbf6e7f

Browse files
committed
Merge pull request #199 from michalbundyra/hotfix/stream-compressed-response
Fix: decompressed response saved into file when streaming
2 parents 5176d6f + 90e8f4e commit dbf6e7f

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ protected function prepareHeaders($body, $uri)
11841184
// Set the Accept-encoding header if not set - depending on whether
11851185
// zlib is available or not.
11861186
if (! $this->getRequest()->getHeaders()->has('Accept-Encoding')) {
1187-
if (function_exists('gzinflate')) {
1187+
if (empty($this->config['outputstream']) && function_exists('gzinflate')) {
11881188
$headers['Accept-Encoding'] = 'gzip, deflate';
11891189
} else {
11901190
$headers['Accept-Encoding'] = 'identity';

test/ClientTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use ReflectionMethod;
1313
use Zend\Http\Client;
1414
use Zend\Http\Client\Adapter\AdapterInterface;
15+
use Zend\Http\Client\Adapter\Curl;
16+
use Zend\Http\Client\Adapter\Proxy;
17+
use Zend\Http\Client\Adapter\Socket;
1518
use Zend\Http\Client\Adapter\Test;
1619
use Zend\Http\Client\Exception as ClientException;
1720
use Zend\Http\Cookies;
@@ -607,4 +610,31 @@ public function testSetCookieAcceptOnlyArray()
607610
$this->expectExceptionMessage('Invalid cookies passed as parameter, it must be an array');
608611
$client->setCookies(new SetCookie('name', 'value'));
609612
}
613+
614+
/**
615+
* @return AdapterInterface[]
616+
*/
617+
public function adapterWithStreamSupport()
618+
{
619+
yield 'curl' => [new Curl()];
620+
yield 'proxy' => [new Proxy()];
621+
yield 'socket' => [new Socket()];
622+
}
623+
624+
/**
625+
* @dataProvider adapterWithStreamSupport
626+
*/
627+
public function testStreamCompression(AdapterInterface $adapter)
628+
{
629+
$tmpFile = tempnam(sys_get_temp_dir(), 'stream');
630+
631+
$client = new Client('https://www.gnu.org/licenses/gpl-3.0.txt');
632+
$client->setAdapter($adapter);
633+
$client->setStream($tmpFile);
634+
$client->send();
635+
636+
$response = $client->getResponse();
637+
638+
self::assertSame($response->getBody(), file_get_contents($tmpFile));
639+
}
610640
}

0 commit comments

Comments
 (0)