Changeset View
Changeset View
Standalone View
Standalone View
src/aphront/response/AphrontFileResponse.php
| <?php | <?php | ||||
| final class AphrontFileResponse extends AphrontResponse { | 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; | ||||
| private $rangeMin; | private $rangeMin; | ||||
| private $rangeMax; | private $rangeMax; | ||||
| private $allowOrigins = array(); | private $allowOrigins = array(); | ||||
| public function addAllowOrigin($origin) { | public function addAllowOrigin($origin) { | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | public function setContentLength($length) { | ||||
| $this->contentLength = $length; | $this->contentLength = $length; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getContentLength() { | public function getContentLength() { | ||||
| 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; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getHeaders() { | public function getHeaders() { | ||||
| $headers = array( | $headers = array( | ||||
| Show All 9 Lines | if ($this->rangeMin || $this->rangeMax) { | ||||
| $min = $this->rangeMin; | $min = $this->rangeMin; | ||||
| $max = $this->rangeMax; | $max = $this->rangeMax; | ||||
| $headers[] = array('Content-Range', "bytes {$min}-{$max}/{$len}"); | $headers[] = array('Content-Range', "bytes {$min}-{$max}/{$len}"); | ||||
| $content_len = ($max - $min) + 1; | $content_len = ($max - $min) + 1; | ||||
| } else { | } else { | ||||
| $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'); | ||||
| $filename = $this->getDownload(); | $filename = $this->getDownload(); | ||||
| $filename = addcslashes($filename, '"\\'); | $filename = addcslashes($filename, '"\\'); | ||||
| $headers[] = array( | $headers[] = array( | ||||
| 'Content-Disposition', | 'Content-Disposition', | ||||
| 'attachment; filename="'.$filename.'"', | 'attachment; filename="'.$filename.'"', | ||||
| ); | ); | ||||
| } | } | ||||
| if ($this->allowOrigins) { | if ($this->allowOrigins) { | ||||
| $headers[] = array( | $headers[] = array( | ||||
| 'Access-Control-Allow-Origin', | 'Access-Control-Allow-Origin', | ||||
| implode(',', $this->allowOrigins), | implode(',', $this->allowOrigins), | ||||
| ); | ); | ||||
| } | } | ||||
| $headers = array_merge(parent::getHeaders(), $headers); | $headers = array_merge(parent::getHeaders(), $headers); | ||||
| return $headers; | return $headers; | ||||
| } | } | ||||
| protected function shouldCompressResponse() { | |||||
| return $this->getCompressResponse(); | |||||
| } | |||||
avivey: maybe also enable the compression on `else`? | |||||
Not Done Inline ActionsIt's enabled globally in PhabricatorStartup and I shudder to think what PHP might do if we enable it twice. It would, perhaps, be cleaner to bring the CompressResponse stuff up a level to AphrontResponse, and have that control zlib.output_compression in all cases, although when we fatal the "¯\_(ツ)_/¯" page won't get compressed. epriestley: It's enabled globally in `PhabricatorStartup` and I shudder to think what PHP might do if we… | |||||
| } | } | ||||
maybe also enable the compression on else?