@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

In Conduit responses, assert that Phabricator supports a "gzip" capability

Summary: Ref T13507. If we believe the server can accept "Content-Encoding: gzip" requests, make the claim in an "X-Conduit-Capabilities" header in responses. Clients can use request compression on subsequent requests.

Test Plan: See D21119 for the client piece.

Maniphest Tasks: T13507

Differential Revision: https://secure.phabricator.com/D21120

+34 -7
+2 -1
src/aphront/requeststream/AphrontRequestStream.php
··· 101 101 102 102 $filters = stream_get_filters(); 103 103 foreach ($filters as $filter) { 104 - if (preg_match('/^zlib\\./', $filter)) { 104 + if (!strncasecmp($filter, 'zlib.', strlen('zlib.'))) { 105 105 $has_zlib = true; 106 + break; 106 107 } 107 108 } 108 109
+4 -4
src/aphront/response/AphrontJSONResponse.php
··· 31 31 } 32 32 33 33 public function getHeaders() { 34 - $headers = array( 35 - array('Content-Type', 'application/json'), 36 - ); 37 - $headers = array_merge(parent::getHeaders(), $headers); 34 + $headers = parent::getHeaders(); 35 + 36 + $headers[] = array('Content-Type', 'application/json'); 37 + 38 38 return $headers; 39 39 } 40 40
+10 -1
src/aphront/response/AphrontResponse.php
··· 10 10 private $contentSecurityPolicyURIs; 11 11 private $disableContentSecurityPolicy; 12 12 protected $frameable; 13 - 13 + private $headers = array(); 14 14 15 15 public function setRequest($request) { 16 16 $this->request = $request; ··· 46 46 47 47 final public function setDisableContentSecurityPolicy($disable) { 48 48 $this->disableContentSecurityPolicy = $disable; 49 + return $this; 50 + } 51 + 52 + final public function addHeader($key, $value) { 53 + $this->headers[] = array($key, $value); 49 54 return $this; 50 55 } 51 56 ··· 104 109 } 105 110 106 111 $headers[] = array('Referrer-Policy', 'no-referrer'); 112 + 113 + foreach ($this->headers as $header) { 114 + $headers[] = $header; 115 + } 107 116 108 117 return $headers; 109 118 }
+18 -1
src/applications/conduit/controller/PhabricatorConduitAPIController.php
··· 134 134 $method_implementation); 135 135 case 'json': 136 136 default: 137 - return id(new AphrontJSONResponse()) 137 + $response = id(new AphrontJSONResponse()) 138 138 ->setAddJSONShield(false) 139 139 ->setContent($response->toDictionary()); 140 + 141 + $capabilities = $this->getConduitCapabilities(); 142 + if ($capabilities) { 143 + $capabilities = implode(' ', $capabilities); 144 + $response->addHeader('X-Conduit-Capabilities', $capabilities); 145 + } 146 + 147 + return $response; 140 148 } 141 149 } 142 150 ··· 716 724 return false; 717 725 } 718 726 727 + private function getConduitCapabilities() { 728 + $capabilities = array(); 729 + 730 + if (AphrontRequestStream::supportsGzip()) { 731 + $capabilities[] = 'gzip'; 732 + } 733 + 734 + return $capabilities; 735 + } 719 736 720 737 }