1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

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
This commit is contained in:
epriestley 2020-04-14 16:45:35 -07:00
parent 6b05d2be28
commit 0ea6d131e0
4 changed files with 34 additions and 7 deletions

View file

@ -101,8 +101,9 @@ final class AphrontRequestStream extends Phobject {
$filters = stream_get_filters();
foreach ($filters as $filter) {
if (preg_match('/^zlib\\./', $filter)) {
if (!strncasecmp($filter, 'zlib.', strlen('zlib.'))) {
$has_zlib = true;
break;
}
}

View file

@ -31,10 +31,10 @@ final class AphrontJSONResponse extends AphrontResponse {
}
public function getHeaders() {
$headers = array(
array('Content-Type', 'application/json'),
);
$headers = array_merge(parent::getHeaders(), $headers);
$headers = parent::getHeaders();
$headers[] = array('Content-Type', 'application/json');
return $headers;
}

View file

@ -10,7 +10,7 @@ abstract class AphrontResponse extends Phobject {
private $contentSecurityPolicyURIs;
private $disableContentSecurityPolicy;
protected $frameable;
private $headers = array();
public function setRequest($request) {
$this->request = $request;
@ -49,6 +49,11 @@ abstract class AphrontResponse extends Phobject {
return $this;
}
final public function addHeader($key, $value) {
$this->headers[] = array($key, $value);
return $this;
}
/* -( Content )------------------------------------------------------------ */
@ -105,6 +110,10 @@ abstract class AphrontResponse extends Phobject {
$headers[] = array('Referrer-Policy', 'no-referrer');
foreach ($this->headers as $header) {
$headers[] = $header;
}
return $headers;
}

View file

@ -134,9 +134,17 @@ final class PhabricatorConduitAPIController
$method_implementation);
case 'json':
default:
return id(new AphrontJSONResponse())
$response = id(new AphrontJSONResponse())
->setAddJSONShield(false)
->setContent($response->toDictionary());
$capabilities = $this->getConduitCapabilities();
if ($capabilities) {
$capabilities = implode(' ', $capabilities);
$response->addHeader('X-Conduit-Capabilities', $capabilities);
}
return $response;
}
}
@ -716,5 +724,14 @@ final class PhabricatorConduitAPIController
return false;
}
private function getConduitCapabilities() {
$capabilities = array();
if (AphrontRequestStream::supportsGzip()) {
$capabilities[] = 'gzip';
}
return $capabilities;
}
}