php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58911 Content not decoded with zlib support and compress enabled
Submitted: 2009-10-21 21:23 UTC Modified: 2010-04-28 02:54 UTC
From: tobias382 at gmail dot com Assigned: mike (profile)
Status: Closed Package: pecl_http (PECL)
PHP Version: 1.6.5 OS: Ubuntu 9.04
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tobias382 at gmail dot com
New email:
PHP Version: OS:

 

 [2009-10-21 21:23 UTC] tobias382 at gmail dot com
Description:
------------
When zlib support is compiled in and the compress option is 
enabled for a request, the response body is not automatically 
decoded. See the expected and actual results, where Accept-
Encoding is set in the request and Content-Encoding is set in 
the response. Rather than $response->getBody() returned a 
decoded result, it returns a still-encoded result.

Reproduce code:
---------------
<?php
$request = new HttpRequest('http://www.google.com/');
$request->setOptions(array('compress' => true));
$request->setHeaders(array(
    'User-Agent' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090910 Ubuntu/9.04 (jaunty) Shiretoko/3.5.3 FirePHP/0.3',
));
$response = $request->send();
echo $request->getRawRequestMessage();
foreach ($response->getHeaders() as $name => $value) {
    echo $name, ': ', $value, PHP_EOL;
}
echo PHP_EOL, $response->getBody();

Expected result:
----------------
GET / HTTP/1.1
Host: www.google.com
Accept: */*
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; 
rv:1.9.1.3) Gecko/20090910 Ubuntu/9.04 (jaunty) 
Shiretoko/3.5.3 FirePHP/0.3
Accept-Encoding: gzip;q=1.0,deflate;q=0.5

Date: Thu, 22 Oct 2009 01:05:58 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=UTF-8
Set-Cookie: Array
Content-Encoding: gzip
Server: gws
Content-Length: 2800
X-Xss-Protection: 0

[decoded content]

Actual result:
--------------
Same as expected result, except that in place of [decoded 
content] is encoded binary data.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-22 02:20 UTC] mike@php.net
Please always specify the package version, not PHP's version, thank you.

This happens because Google does not send a Vary header,
but we depend on a Vary header being present for the
content decoder to fire.

Once there was a reason why it is implemented this way,
though I can't rember why ATM.
 [2009-10-22 07:55 UTC] tobias382 at gmail dot com
Sorry, package version is 1.6.5. Google doesn't reply with a 
Vary header for cURL either, but cURL decodes the response 
body.

Sample Code:
<?php
$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL => 'http://www.google.com/',
    CURLOPT_ENCODING => 'gzip,deflate',
    CURLOPT_HEADER => true,
    CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; U; Intel 
Mac OS X 10_5_7; en-US) AppleWebKit/531.0 (KHTML, like 
Gecko) Chrome/3.0.183 Safari/531.0'
));
curl_exec($ch);

Response:
HTTP/1.1 200 OK
Date: Thu, 22 Oct 2009 11:52:14 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=UTF-8
Set-Cookie: 
PREF=ID=1c06cf0b64adab2f:TM=1256212334:LM=1256212334:S=7qoxr
egZxDe95mIG; expires=Sat, 22-Oct-2011 11:52:14 GMT; path=/; 
domain=.google.com
Set-Cookie: NID=28=j2xmJflnhq2CiQRRDbldLmIIpSE5SZgSa-xp-
3BXdUeBwnngWnBOJ3SzHaXurV8oM2n3cSdftyVy9AHH-
7AubTd6BlTvRNSa37vp6P__vzUpvd_tVazHzK5H66ZosLJ5; 
expires=Fri, 23-Apr-2010 11:52:14 GMT; path=/; 
domain=.google.com; HttpOnly
Content-Encoding: gzip
Server: gws
Content-Length: 3080
X-XSS-Protection: 0

[decoded body]
 [2010-04-28 02:54 UTC] mike@php.net
This bug has been fixed in SVN.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 09 10:01:27 2024 UTC