Changeset View
Changeset View
Standalone View
Standalone View
src/aphront/response/AphrontFileResponse.php
Show All 13 Lines | final class AphrontFileResponse extends AphrontResponse { | ||||
private $allowOrigins = array(); | private $allowOrigins = array(); | ||||
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 ($download === null || !strlen($download)) { | ||||
$download = 'untitled'; | $download = 'untitled'; | ||||
} | } | ||||
$this->download = $download; | $this->download = $download; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getDownload() { | public function getDownload() { | ||||
return $this->download; | return $this->download; | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | public function getHeaders() { | ||||
} else { | } else { | ||||
$content_len = $this->getContentLength(); | $content_len = $this->getContentLength(); | ||||
} | } | ||||
if (!$this->shouldCompressResponse()) { | if (!$this->shouldCompressResponse()) { | ||||
$headers[] = array('Content-Length', $content_len); | $headers[] = array('Content-Length', $content_len); | ||||
} | } | ||||
if (strlen($this->getDownload())) { | $download = $this->getDownload(); | ||||
if ($download !== null && strlen($download)) { | |||||
$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.'"', | ||||
); | ); | ||||
Show All 20 Lines | public function parseHTTPRange($range) { | ||||
$matches = null; | $matches = null; | ||||
if (preg_match('/^bytes=(\d+)-(\d*)$/', $range, $matches)) { | if (preg_match('/^bytes=(\d+)-(\d*)$/', $range, $matches)) { | ||||
// Note that the "Range" header specifies bytes differently than | // Note that the "Range" header specifies bytes differently than | ||||
// we do internally: the range 0-1 has 2 bytes (byte 0 and byte 1). | // we do internally: the range 0-1 has 2 bytes (byte 0 and byte 1). | ||||
$begin = (int)$matches[1]; | $begin = (int)$matches[1]; | ||||
// The "Range" may be "200-299" or "200-", meaning "until end of file". | // The "Range" may be "200-299" or "200-", meaning "until end of file". | ||||
if (strlen($matches[2])) { | if ($matches[2] !== null && strlen($matches[2])) { | ||||
$range_end = (int)$matches[2]; | $range_end = (int)$matches[2]; | ||||
$end = $range_end + 1; | $end = $range_end + 1; | ||||
} else { | } else { | ||||
$range_end = null; | $range_end = null; | ||||
} | } | ||||
$this->setHTTPResponseCode(206); | $this->setHTTPResponseCode(206); | ||||
$this->setRange($begin, $range_end); | $this->setRange($begin, $range_end); | ||||
} | } | ||||
return array($begin, $end); | return array($begin, $end); | ||||
} | } | ||||
} | } |