From 7e25288f496887a78d1ba4a54753c2cca09a6336 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 8 Apr 2020 09:19:32 -0700 Subject: [PATCH] Compress requests from the Conduit client to Phabricator Summary: Ref T13507. Enable compression in the body of Conduit requests if we have client support for it; we expect the server should always support it. Test Plan: Created this revision, ran random "arc" commands that use Conduit. Added debugging code, saw payload size drop. Maniphest Tasks: T13507 Differential Revision: https://secure.phabricator.com/D21073 --- src/conduit/ConduitClient.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/conduit/ConduitClient.php b/src/conduit/ConduitClient.php index 065a42ab..8c6c6ad8 100644 --- a/src/conduit/ConduitClient.php +++ b/src/conduit/ConduitClient.php @@ -143,12 +143,25 @@ final class ConduitClient extends Phobject { // Always use the cURL-based HTTPSFuture, for proxy support and other // protocol edge cases that HTTPFuture does not support. - $core_future = new HTTPSFuture($uri, $data); + $core_future = new HTTPSFuture($uri); $core_future->addHeader('Host', $this->getHostStringForHeader()); $core_future->setMethod('POST'); $core_future->setTimeout($this->timeout); + // See T13507. If possible, try to compress requests. We always expect + // Phabricator to be able to accept "Content-Encoding: gzip" requests. + $can_gzip = function_exists('gzencode'); + if ($can_gzip) { + $gzip_data = phutil_build_http_querystring($data); + $gzip_data = gzencode($gzip_data); + + $core_future->addHeader('Content-Encoding', 'gzip'); + $core_future->setData($gzip_data); + } else { + $core_future->setData($data); + } + if ($this->username !== null) { $core_future->setHTTPBasicAuthCredentials( $this->username,