|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 UTC |
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]