Make "Range" HTTP header work for Celerity static resource requests

Summary:
Ref T7567. In T8266 I fixed a bunch of obscure "Range" issues, but only for file downloads -- not for Celerity.

Extend all that stuff to Celerity, which is fortunately much easier.

I believe this will fix Conpherence sounds in Safari.

Test Plan:
  - Wrote out an HTTP request in a text file with `Range: bytes=0-1` and similar, piped it to localhost with `cat request.txt | nc localhost 80`, saw server return appropriate range responses consistent with file behavior after T8266, which all seems to work.
  - Also did that for files to try to make sure I wasn't breaking anything.

Reviewers: chad, amckinley

Reviewed By: chad

Maniphest Tasks: T7567

Differential Revision: https://secure.phabricator.com/D17724
This commit is contained in:
epriestley
2017-04-18 13:17:39 -07:00
parent ece9579d25
commit b479941ceb
3 changed files with 51 additions and 21 deletions

View File

@@ -104,9 +104,30 @@ abstract class CelerityResourceController extends PhabricatorController {
}
$response = id(new AphrontFileResponse())
->setContent($data)
->setMimeType($type_map[$type])
->setCompressResponse(true);
->setMimeType($type_map[$type]);
$range = AphrontRequest::getHTTPHeader('Range');
if (strlen($range)) {
$response->setContentLength(strlen($data));
list($range_begin, $range_end) = $response->parseHTTPRange($range);
if ($range_begin !== null) {
if ($range_end !== null) {
$data = substr($data, $range_begin, ($range_end - $range_begin));
} else {
$data = substr($data, $range_begin);
}
}
$response->setContentIterator(array($data));
} else {
$response
->setContent($data)
->setCompressResponse(true);
}
// NOTE: This is a piece of magic required to make WOFF fonts work in
// Firefox and IE. Possibly we should generalize this more.