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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user