Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/controller/PhabricatorFileDataController.php
| Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | public function handleRequest(AphrontRequest $request) { | ||||
| $end = null; | $end = null; | ||||
| // NOTE: It's important to accept "Range" requests when playing audio. | // NOTE: It's important to accept "Range" requests when playing audio. | ||||
| // If we don't, Safari has difficulty figuring out how long sounds are | // If we don't, Safari has difficulty figuring out how long sounds are | ||||
| // and glitches when trying to loop them. In particular, Safari sends | // and glitches when trying to loop them. In particular, Safari sends | ||||
| // an initial request for bytes 0-1 of the audio file, and things go south | // an initial request for bytes 0-1 of the audio file, and things go south | ||||
| // if we can't respond with a 206 Partial Content. | // if we can't respond with a 206 Partial Content. | ||||
| $range = $request->getHTTPHeader('range'); | $range = $request->getHTTPHeader('range'); | ||||
| if ($range) { | if (strlen($range)) { | ||||
| $matches = null; | list($begin, $end) = $response->parseHTTPRange($range); | ||||
| if (preg_match('/^bytes=(\d+)-(\d*)$/', $range, $matches)) { | |||||
| // Note that the "Range" header specifies bytes differently than | |||||
| // we do internally: the range 0-1 has 2 bytes (byte 0 and byte 1). | |||||
| $begin = (int)$matches[1]; | |||||
| // The "Range" may be "200-299" or "200-", meaning "until end of file". | |||||
| if (strlen($matches[2])) { | |||||
| $range_end = (int)$matches[2]; | |||||
| $end = $range_end + 1; | |||||
| } else { | |||||
| $range_end = null; | |||||
| } | |||||
| $response->setHTTPResponseCode(206); | |||||
| $response->setRange($begin, $range_end); | |||||
| } | |||||
| } | } | ||||
| $is_viewable = $file->isViewableInBrowser(); | $is_viewable = $file->isViewableInBrowser(); | ||||
| $force_download = $request->getExists('download'); | $force_download = $request->getExists('download'); | ||||
| $request_type = $request->getHTTPHeader('X-Phabricator-Request-Type'); | $request_type = $request->getHTTPHeader('X-Phabricator-Request-Type'); | ||||
| $is_lfs = ($request_type == 'git-lfs'); | $is_lfs = ($request_type == 'git-lfs'); | ||||
| ▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines | |||||