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

Zend\Http\Response::getBody() tries to decode gzip that has already been decoded by cURL #4555

Closed

Conversation

weierophinney
Copy link
Member

When performing a HTTP request to a gzipped resource via a cURL adapter that is configured to decode content, a following call to $httpResponse->getBody() fails because it looks at the still-set Content-Encoding header and tries to decode the content, which is at that point already decoded, again.

You can reproduce it like this:

$httpClient = new Zend\Http\Client($urlWithGzipEncodedStuff,  [
    'adapter'      => 'Zend\Http\Client\Adapter\Curl',
    'curloptions'  => [
        // Instruct cURL to accept and decode any supported encoding.
        CURLOPT_ENCODING => '' 
    ]
]);
$httpResponse = $httpClient->send();

// BOOM: tries to decode what has already been decoded by  cURL
$content = $httpResponse->getBody();

- cURL's CURLOPT_ENCODING setting can allow auto-decoding a response.
  Detect if set appropriately, and, if so, strip the Content-Encoding
  header in the response.
@weierophinney
Copy link
Member

These tests won't get run by Travis. To verify them, do the following:

  • Copy tests/TestConfiguration.php.dist to tests/TestConfiguration.php
  • Edit tests/TestConfiguration.php, and alter the following entries:
defined('TESTS_ZEND_HTTP_CLIENT_BASEURI') || define('TESTS_ZEND_HTTP_CLIENT_BASEURI', 'http://localhost:8080'); // alter to a URI you can use; localhost also works
defined('TESTS_ZEND_HTTP_CLIENT_ONLINE') || define('TESTS_ZEND_HTTP_CLIENT_ONLINE', true);
  • Descend into tests/ZendTest/Zend/Http/Client/_files/ and start the built-in PHP web server:
php -S localhost:8080
  • From the tests directory, run the cURL client tests; I was getting an infinite loop somewhere, so ran only this group: phpunit --group 4555 ZendTest/Http/Client/CurlTest.php

mwillbanks pushed a commit that referenced this pull request Jul 23, 2013
weierophinney added a commit to zendframework/zend-http that referenced this pull request May 15, 2015
…nses via cURL

- cURL's CURLOPT_ENCODING setting can allow auto-decoding a response.
  Detect if set appropriately, and, if so, strip the Content-Encoding
  header in the response.
gianarb pushed a commit to zendframework/zend-http that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-http that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant