mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Don't combine automatic output compression with "Content-Length"
Summary: Fixes T12013. Send either "Content-Length" or enable output compression, but not both. Prefer compression for static resources (CSS, JS, etc). Test Plan: Ran `curl -v ...`, no longer saw responses with both compression and `Content-Length`. Reviewers: chad, avivey Reviewed By: avivey Subscribers: avivey Maniphest Tasks: T12013 Differential Revision: https://secure.phabricator.com/D17045
This commit is contained in:
parent
26127b9c5f
commit
842710608e
5 changed files with 38 additions and 9 deletions
|
@ -5,6 +5,7 @@ final class AphrontFileResponse extends AphrontResponse {
|
||||||
private $content;
|
private $content;
|
||||||
private $contentIterator;
|
private $contentIterator;
|
||||||
private $contentLength;
|
private $contentLength;
|
||||||
|
private $compressResponse;
|
||||||
|
|
||||||
private $mimeType;
|
private $mimeType;
|
||||||
private $download;
|
private $download;
|
||||||
|
@ -69,6 +70,15 @@ final class AphrontFileResponse extends AphrontResponse {
|
||||||
return $this->contentLength;
|
return $this->contentLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setCompressResponse($compress_response) {
|
||||||
|
$this->compressResponse = $compress_response;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCompressResponse() {
|
||||||
|
return $this->compressResponse;
|
||||||
|
}
|
||||||
|
|
||||||
public function setRange($min, $max) {
|
public function setRange($min, $max) {
|
||||||
$this->rangeMin = $min;
|
$this->rangeMin = $min;
|
||||||
$this->rangeMax = $max;
|
$this->rangeMax = $max;
|
||||||
|
@ -94,7 +104,9 @@ final class AphrontFileResponse extends AphrontResponse {
|
||||||
$content_len = $this->getContentLength();
|
$content_len = $this->getContentLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->shouldCompressResponse()) {
|
||||||
$headers[] = array('Content-Length', $this->getContentLength());
|
$headers[] = array('Content-Length', $this->getContentLength());
|
||||||
|
}
|
||||||
|
|
||||||
if (strlen($this->getDownload())) {
|
if (strlen($this->getDownload())) {
|
||||||
$headers[] = array('X-Download-Options', 'noopen');
|
$headers[] = array('X-Download-Options', 'noopen');
|
||||||
|
@ -118,4 +130,8 @@ final class AphrontFileResponse extends AphrontResponse {
|
||||||
return $headers;
|
return $headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function shouldCompressResponse() {
|
||||||
|
return $this->getCompressResponse();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,6 +242,21 @@ abstract class AphrontResponse extends Phobject {
|
||||||
return gmdate('D, d M Y H:i:s', $epoch_timestamp).' GMT';
|
return gmdate('D, d M Y H:i:s', $epoch_timestamp).' GMT';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function shouldCompressResponse() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function willBeginWrite() {
|
||||||
|
if ($this->shouldCompressResponse()) {
|
||||||
|
// Enable automatic compression here. Webservers sometimes do this for
|
||||||
|
// us, but we now detect the absence of compression and warn users about
|
||||||
|
// it so try to cover our bases more thoroughly.
|
||||||
|
ini_set('zlib.output_compression', 1);
|
||||||
|
} else {
|
||||||
|
ini_set('zlib.output_compression', 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function didCompleteWrite($aborted) {
|
public function didCompleteWrite($aborted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,8 @@ abstract class AphrontHTTPSink extends Phobject {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
final public function writeResponse(AphrontResponse $response) {
|
final public function writeResponse(AphrontResponse $response) {
|
||||||
|
$response->willBeginWrite();
|
||||||
|
|
||||||
// Build the content iterator first, in case it throws. Ideally, we'd
|
// Build the content iterator first, in case it throws. Ideally, we'd
|
||||||
// prefer to handle exceptions before we emit the response status or any
|
// prefer to handle exceptions before we emit the response status or any
|
||||||
// HTTP headers.
|
// HTTP headers.
|
||||||
|
|
|
@ -103,9 +103,10 @@ abstract class CelerityResourceController extends PhabricatorController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = new AphrontFileResponse();
|
$response = id(new AphrontFileResponse())
|
||||||
$response->setContent($data);
|
->setContent($data)
|
||||||
$response->setMimeType($type_map[$type]);
|
->setMimeType($type_map[$type])
|
||||||
|
->setCompressResponse(true);
|
||||||
|
|
||||||
// NOTE: This is a piece of magic required to make WOFF fonts work in
|
// NOTE: This is a piece of magic required to make WOFF fonts work in
|
||||||
// Firefox and IE. Possibly we should generalize this more.
|
// Firefox and IE. Possibly we should generalize this more.
|
||||||
|
|
|
@ -395,11 +395,6 @@ final class PhabricatorStartup {
|
||||||
if (function_exists('libxml_disable_entity_loader')) {
|
if (function_exists('libxml_disable_entity_loader')) {
|
||||||
libxml_disable_entity_loader(true);
|
libxml_disable_entity_loader(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable automatic compression here. Webservers sometimes do this for
|
|
||||||
// us, but we now detect the absence of compression and warn users about
|
|
||||||
// it so try to cover our bases more thoroughly.
|
|
||||||
ini_set('zlib.output_compression', 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue