mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-28 17:52:42 +01:00
If the Conduit client supports gzip, make calls with "Accept-Encoding: gzip"
Summary: Ref T13507. Add "Accept-Encoding: gzip" to requests if we can decompress responses. When we receive a compressed response, decompress it. Test Plan: Added debugging code, ran some commands, saw smaller payloads over the wire and inline decompression. Maniphest Tasks: T13507 Differential Revision: https://secure.phabricator.com/D21118
This commit is contained in:
parent
890b57de1e
commit
a77da426af
2 changed files with 38 additions and 1 deletions
|
@ -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,
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue