Page MenuHomePhabricator

D17045.id.diff
No OneTemporary

D17045.id.diff

diff --git a/src/aphront/response/AphrontFileResponse.php b/src/aphront/response/AphrontFileResponse.php
--- a/src/aphront/response/AphrontFileResponse.php
+++ b/src/aphront/response/AphrontFileResponse.php
@@ -5,6 +5,7 @@
private $content;
private $contentIterator;
private $contentLength;
+ private $compressResponse;
private $mimeType;
private $download;
@@ -69,6 +70,15 @@
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) {
$this->rangeMin = $min;
$this->rangeMax = $max;
@@ -94,7 +104,9 @@
$content_len = $this->getContentLength();
}
- $headers[] = array('Content-Length', $this->getContentLength());
+ if (!$this->shouldCompressResponse()) {
+ $headers[] = array('Content-Length', $this->getContentLength());
+ }
if (strlen($this->getDownload())) {
$headers[] = array('X-Download-Options', 'noopen');
@@ -118,4 +130,8 @@
return $headers;
}
+ protected function shouldCompressResponse() {
+ return $this->getCompressResponse();
+ }
+
}
diff --git a/src/aphront/response/AphrontResponse.php b/src/aphront/response/AphrontResponse.php
--- a/src/aphront/response/AphrontResponse.php
+++ b/src/aphront/response/AphrontResponse.php
@@ -242,6 +242,21 @@
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) {
return;
}
diff --git a/src/aphront/sink/AphrontHTTPSink.php b/src/aphront/sink/AphrontHTTPSink.php
--- a/src/aphront/sink/AphrontHTTPSink.php
+++ b/src/aphront/sink/AphrontHTTPSink.php
@@ -96,6 +96,8 @@
* @return void
*/
final public function writeResponse(AphrontResponse $response) {
+ $response->willBeginWrite();
+
// Build the content iterator first, in case it throws. Ideally, we'd
// prefer to handle exceptions before we emit the response status or any
// HTTP headers.
diff --git a/src/applications/celerity/controller/CelerityResourceController.php b/src/applications/celerity/controller/CelerityResourceController.php
--- a/src/applications/celerity/controller/CelerityResourceController.php
+++ b/src/applications/celerity/controller/CelerityResourceController.php
@@ -103,9 +103,10 @@
}
}
- $response = new AphrontFileResponse();
- $response->setContent($data);
- $response->setMimeType($type_map[$type]);
+ $response = id(new AphrontFileResponse())
+ ->setContent($data)
+ ->setMimeType($type_map[$type])
+ ->setCompressResponse(true);
// NOTE: This is a piece of magic required to make WOFF fonts work in
// Firefox and IE. Possibly we should generalize this more.
diff --git a/support/PhabricatorStartup.php b/support/PhabricatorStartup.php
--- a/support/PhabricatorStartup.php
+++ b/support/PhabricatorStartup.php
@@ -395,11 +395,6 @@
if (function_exists('libxml_disable_entity_loader')) {
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);
}

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 16, 4:12 PM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7374353
Default Alt Text
D17045.id.diff (3 KB)

Event Timeline