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 $mimeType; | private $mimeType; | ||||
| private $download; | private $download; | ||||
| private $rangeMin; | private $rangeMin; | ||||
| private $rangeMax; | private $rangeMax; | ||||
| private $allowOrigins = array(); | private $allowOrigins = array(); | ||||
| private $fileToken; | |||||
| public function addAllowOrigin($origin) { | public function addAllowOrigin($origin) { | ||||
| $this->allowOrigins[] = $origin; | $this->allowOrigins[] = $origin; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function setDownload($download) { | public function setDownload($download) { | ||||
| if (!strlen($download)) { | if (!strlen($download)) { | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | final class AphrontFileResponse extends AphrontResponse { | ||||
| } | } | ||||
| 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 setTemporaryFileToken(PhabricatorAuthTemporaryToken $token) { | |||||
| $this->fileToken = $token; | |||||
| return $this; | |||||
| } | |||||
| public function getTemporaryFileToken() { | |||||
| return $this->fileToken; | |||||
| } | |||||
| public function getHeaders() { | public function getHeaders() { | ||||
| $headers = array( | $headers = array( | ||||
| array('Content-Type', $this->getMimeType()), | array('Content-Type', $this->getMimeType()), | ||||
| // This tells clients that we can support requests with a "Range" header, | // This tells clients that we can support requests with a "Range" header, | ||||
| // which allows downloads to be resumed, in some browsers, some of the | // which allows downloads to be resumed, in some browsers, some of the | ||||
| // time, if the stars align. | // time, if the stars align. | ||||
| array('Accept-Ranges', 'bytes'), | array('Accept-Ranges', 'bytes'), | ||||
| ); | ); | ||||
| Show All 27 Lines | if ($this->allowOrigins) { | ||||
| implode(',', $this->allowOrigins), | implode(',', $this->allowOrigins), | ||||
| ); | ); | ||||
| } | } | ||||
| $headers = array_merge(parent::getHeaders(), $headers); | $headers = array_merge(parent::getHeaders(), $headers); | ||||
| return $headers; | return $headers; | ||||
| } | } | ||||
| public function didCompleteWrite($aborted) { | |||||
| if (!$aborted) { | |||||
| $token = $this->getTemporaryFileToken(); | |||||
| if ($token) { | |||||
| $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | |||||
| $token->delete(); | |||||
| unset($unguarded); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||