diff --git a/src/future/http/BaseHTTPFuture.php b/src/future/http/BaseHTTPFuture.php index 591cf781..5d0c0f80 100644 --- a/src/future/http/BaseHTTPFuture.php +++ b/src/future/http/BaseHTTPFuture.php @@ -348,6 +348,26 @@ abstract class BaseHTTPFuture extends Future { } } + $content_encoding = null; + foreach ($headers as $header) { + list($name, $value) = $header; + $name = phutil_utf8_strtolower($name); + if (!strcasecmp($name, 'Content-Encoding')) { + $content_encoding = $value; + break; + } + } + + switch ($content_encoding) { + case 'gzip': + $decoded_body = gzdecode($body); + if ($decoded_body === false) { + return $this->buildMalformedResult($raw_response); + } + $body = $decoded_body; + break; + } + $status = new HTTPFutureHTTPResponseStatus( $response_code, $body, diff --git a/src/future/http/HTTPSFuture.php b/src/future/http/HTTPSFuture.php index 70804332..5b9dd7b0 100644 --- a/src/future/http/HTTPSFuture.php +++ b/src/future/http/HTTPSFuture.php @@ -280,12 +280,16 @@ final class HTTPSFuture extends BaseHTTPFuture { $headers = $this->getHeaders(); $saw_expect = false; + $saw_accept = false; for ($ii = 0; $ii < count($headers); $ii++) { list($name, $value) = $headers[$ii]; $headers[$ii] = $name.': '.$value; - if (!strncasecmp($name, 'Expect', strlen('Expect'))) { + if (!strcasecmp($name, 'Expect')) { $saw_expect = true; } + if (!strcasecmp($name, 'Accept-Encoding')) { + $saw_accept = true; + } } if (!$saw_expect) { // cURL sends an "Expect" header by default for certain requests. While @@ -302,6 +306,15 @@ final class HTTPSFuture extends BaseHTTPFuture { // http://curl.haxx.se/mail/archive-2009-07/0008.html $headers[] = 'Expect:'; } + + if (!$saw_accept) { + if (!$use_streaming_parser) { + if ($this->canAcceptGzip()) { + $headers[] = 'Accept-Encoding: gzip'; + } + } + } + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); // Set the requested HTTP method, e.g. GET / POST / PUT. @@ -821,4 +834,8 @@ final class HTTPSFuture extends BaseHTTPFuture { ); } + private function canAcceptGzip() { + return function_exists('gzdecode'); + } + }