@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+38 -9
+17 -1
src/aphront/response/AphrontFileResponse.php
··· 5 5 private $content; 6 6 private $contentIterator; 7 7 private $contentLength; 8 + private $compressResponse; 8 9 9 10 private $mimeType; 10 11 private $download; ··· 69 70 return $this->contentLength; 70 71 } 71 72 73 + public function setCompressResponse($compress_response) { 74 + $this->compressResponse = $compress_response; 75 + return $this; 76 + } 77 + 78 + public function getCompressResponse() { 79 + return $this->compressResponse; 80 + } 81 + 72 82 public function setRange($min, $max) { 73 83 $this->rangeMin = $min; 74 84 $this->rangeMax = $max; ··· 94 104 $content_len = $this->getContentLength(); 95 105 } 96 106 97 - $headers[] = array('Content-Length', $this->getContentLength()); 107 + if (!$this->shouldCompressResponse()) { 108 + $headers[] = array('Content-Length', $this->getContentLength()); 109 + } 98 110 99 111 if (strlen($this->getDownload())) { 100 112 $headers[] = array('X-Download-Options', 'noopen'); ··· 116 128 117 129 $headers = array_merge(parent::getHeaders(), $headers); 118 130 return $headers; 131 + } 132 + 133 + protected function shouldCompressResponse() { 134 + return $this->getCompressResponse(); 119 135 } 120 136 121 137 }
+15
src/aphront/response/AphrontResponse.php
··· 242 242 return gmdate('D, d M Y H:i:s', $epoch_timestamp).' GMT'; 243 243 } 244 244 245 + protected function shouldCompressResponse() { 246 + return true; 247 + } 248 + 249 + public function willBeginWrite() { 250 + if ($this->shouldCompressResponse()) { 251 + // Enable automatic compression here. Webservers sometimes do this for 252 + // us, but we now detect the absence of compression and warn users about 253 + // it so try to cover our bases more thoroughly. 254 + ini_set('zlib.output_compression', 1); 255 + } else { 256 + ini_set('zlib.output_compression', 0); 257 + } 258 + } 259 + 245 260 public function didCompleteWrite($aborted) { 246 261 return; 247 262 }
+2
src/aphront/sink/AphrontHTTPSink.php
··· 96 96 * @return void 97 97 */ 98 98 final public function writeResponse(AphrontResponse $response) { 99 + $response->willBeginWrite(); 100 + 99 101 // Build the content iterator first, in case it throws. Ideally, we'd 100 102 // prefer to handle exceptions before we emit the response status or any 101 103 // HTTP headers.
+4 -3
src/applications/celerity/controller/CelerityResourceController.php
··· 103 103 } 104 104 } 105 105 106 - $response = new AphrontFileResponse(); 107 - $response->setContent($data); 108 - $response->setMimeType($type_map[$type]); 106 + $response = id(new AphrontFileResponse()) 107 + ->setContent($data) 108 + ->setMimeType($type_map[$type]) 109 + ->setCompressResponse(true); 109 110 110 111 // NOTE: This is a piece of magic required to make WOFF fonts work in 111 112 // Firefox and IE. Possibly we should generalize this more.
-5
support/PhabricatorStartup.php
··· 395 395 if (function_exists('libxml_disable_entity_loader')) { 396 396 libxml_disable_entity_loader(true); 397 397 } 398 - 399 - // Enable automatic compression here. Webservers sometimes do this for 400 - // us, but we now detect the absence of compression and warn users about 401 - // it so try to cover our bases more thoroughly. 402 - ini_set('zlib.output_compression', 1); 403 398 } 404 399 405 400