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();
|
$filters = stream_get_filters();
|
||||||
foreach ($filters as $filter) {
|
foreach ($filters as $filter) {
|
||||||
if (preg_match('/^zlib\\./', $filter)) {
|
if (!strncasecmp($filter, 'zlib.', strlen('zlib.'))) {
|
||||||
$has_zlib = true;
|
$has_zlib = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ final class AphrontJSONResponse extends AphrontResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getHeaders() {
|
public function getHeaders() {
|
||||||
$headers = array(
|
$headers = parent::getHeaders();
|
||||||
array('Content-Type', 'application/json'),
|
|
||||||
);
|
$headers[] = array('Content-Type', 'application/json');
|
||||||
$headers = array_merge(parent::getHeaders(), $headers);
|
|
||||||
return $headers;
|
return $headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ abstract class AphrontResponse extends Phobject {
|
|||||||
private $contentSecurityPolicyURIs;
|
private $contentSecurityPolicyURIs;
|
||||||
private $disableContentSecurityPolicy;
|
private $disableContentSecurityPolicy;
|
||||||
protected $frameable;
|
protected $frameable;
|
||||||
|
private $headers = array();
|
||||||
|
|
||||||
public function setRequest($request) {
|
public function setRequest($request) {
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
@@ -49,6 +49,11 @@ abstract class AphrontResponse extends Phobject {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final public function addHeader($key, $value) {
|
||||||
|
$this->headers[] = array($key, $value);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( Content )------------------------------------------------------------ */
|
/* -( Content )------------------------------------------------------------ */
|
||||||
|
|
||||||
@@ -105,6 +110,10 @@ abstract class AphrontResponse extends Phobject {
|
|||||||
|
|
||||||
$headers[] = array('Referrer-Policy', 'no-referrer');
|
$headers[] = array('Referrer-Policy', 'no-referrer');
|
||||||
|
|
||||||
|
foreach ($this->headers as $header) {
|
||||||
|
$headers[] = $header;
|
||||||
|
}
|
||||||
|
|
||||||
return $headers;
|
return $headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,9 +134,17 @@ final class PhabricatorConduitAPIController
|
|||||||
$method_implementation);
|
$method_implementation);
|
||||||
case 'json':
|
case 'json':
|
||||||
default:
|
default:
|
||||||
return id(new AphrontJSONResponse())
|
$response = id(new AphrontJSONResponse())
|
||||||
->setAddJSONShield(false)
|
->setAddJSONShield(false)
|
||||||
->setContent($response->toDictionary());
|
->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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getConduitCapabilities() {
|
||||||
|
$capabilities = array();
|
||||||
|
|
||||||
|
if (AphrontRequestStream::supportsGzip()) {
|
||||||
|
$capabilities[] = 'gzip';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $capabilities;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user