@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+51 -21
+25
src/aphront/response/AphrontFileResponse.php
··· 139 139 return $this->getCompressResponse(); 140 140 } 141 141 142 + public function parseHTTPRange($range) { 143 + $begin = null; 144 + $end = null; 145 + 146 + $matches = null; 147 + if (preg_match('/^bytes=(\d+)-(\d*)$/', $range, $matches)) { 148 + // Note that the "Range" header specifies bytes differently than 149 + // we do internally: the range 0-1 has 2 bytes (byte 0 and byte 1). 150 + $begin = (int)$matches[1]; 151 + 152 + // The "Range" may be "200-299" or "200-", meaning "until end of file". 153 + if (strlen($matches[2])) { 154 + $range_end = (int)$matches[2]; 155 + $end = $range_end + 1; 156 + } else { 157 + $range_end = null; 158 + } 159 + 160 + $this->setHTTPResponseCode(206); 161 + $this->setRange($begin, $range_end); 162 + } 163 + 164 + return array($begin, $end); 165 + } 166 + 142 167 }
+24 -3
src/applications/celerity/controller/CelerityResourceController.php
··· 104 104 } 105 105 106 106 $response = id(new AphrontFileResponse()) 107 - ->setContent($data) 108 - ->setMimeType($type_map[$type]) 109 - ->setCompressResponse(true); 107 + ->setMimeType($type_map[$type]); 108 + 109 + $range = AphrontRequest::getHTTPHeader('Range'); 110 + 111 + if (strlen($range)) { 112 + $response->setContentLength(strlen($data)); 113 + 114 + list($range_begin, $range_end) = $response->parseHTTPRange($range); 115 + 116 + if ($range_begin !== null) { 117 + if ($range_end !== null) { 118 + $data = substr($data, $range_begin, ($range_end - $range_begin)); 119 + } else { 120 + $data = substr($data, $range_begin); 121 + } 122 + } 123 + 124 + $response->setContentIterator(array($data)); 125 + } else { 126 + $response 127 + ->setContent($data) 128 + ->setCompressResponse(true); 129 + } 130 + 110 131 111 132 // NOTE: This is a piece of magic required to make WOFF fonts work in 112 133 // Firefox and IE. Possibly we should generalize this more.
+2 -18
src/applications/files/controller/PhabricatorFileDataController.php
··· 62 62 // an initial request for bytes 0-1 of the audio file, and things go south 63 63 // if we can't respond with a 206 Partial Content. 64 64 $range = $request->getHTTPHeader('range'); 65 - if ($range) { 66 - $matches = null; 67 - if (preg_match('/^bytes=(\d+)-(\d*)$/', $range, $matches)) { 68 - // Note that the "Range" header specifies bytes differently than 69 - // we do internally: the range 0-1 has 2 bytes (byte 0 and byte 1). 70 - $begin = (int)$matches[1]; 71 - 72 - // The "Range" may be "200-299" or "200-", meaning "until end of file". 73 - if (strlen($matches[2])) { 74 - $range_end = (int)$matches[2]; 75 - $end = $range_end + 1; 76 - } else { 77 - $range_end = null; 78 - } 79 - 80 - $response->setHTTPResponseCode(206); 81 - $response->setRange($begin, $range_end); 82 - } 65 + if (strlen($range)) { 66 + list($begin, $end) = $response->parseHTTPRange($range); 83 67 } 84 68 85 69 $is_viewable = $file->isViewableInBrowser();