@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.

Support "Range: bytes=123-" requests

Summary:
Ref T12219. We currently only support Range requests like "bytes=123-456", but "bytes=123-", meaning "until end of file", is valid, and Chrome can send these requests.

I suspect this is the issue with T12219.

Test Plan: Used `nc local.phacility.com 80` to pipe raw requests, saw both "bytes=123-456" and "bytes=123-" requests satisfied correctly.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12219

Differential Revision: https://secure.phabricator.com/D17626

+23 -3
+5
src/aphront/response/AphrontFileResponse.php
··· 97 97 if ($this->rangeMin || $this->rangeMax) { 98 98 $len = $this->getContentLength(); 99 99 $min = $this->rangeMin; 100 + 100 101 $max = $this->rangeMax; 102 + if ($max === null) { 103 + $max = ($len - 1); 104 + } 105 + 101 106 $headers[] = array('Content-Range', "bytes {$min}-{$max}/{$len}"); 102 107 $content_len = ($max - $min) + 1; 103 108 } else {
+10 -3
src/applications/files/controller/PhabricatorFileDataController.php
··· 64 64 $range = $request->getHTTPHeader('range'); 65 65 if ($range) { 66 66 $matches = null; 67 - if (preg_match('/^bytes=(\d+)-(\d+)$/', $range, $matches)) { 67 + if (preg_match('/^bytes=(\d+)-(\d*)$/', $range, $matches)) { 68 68 // Note that the "Range" header specifies bytes differently than 69 69 // we do internally: the range 0-1 has 2 bytes (byte 0 and byte 1). 70 70 $begin = (int)$matches[1]; 71 - $end = (int)$matches[2] + 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 + } 72 79 73 80 $response->setHTTPResponseCode(206); 74 - $response->setRange($begin, ($end - 1)); 81 + $response->setRange($begin, $range_end); 75 82 } 76 83 } 77 84
+8
src/applications/files/format/__tests__/PhabricatorFileStorageFormatTestCase.php
··· 91 91 $raw_data .= $data_chunk; 92 92 } 93 93 $this->assertEqual('cow jumped', $raw_data); 94 + 95 + $iterator = $file->getFileDataIterator(4, null); 96 + $raw_data = ''; 97 + foreach ($iterator as $data_chunk) { 98 + $raw_data .= $data_chunk; 99 + } 100 + $this->assertEqual('cow jumped over the full moon.', $raw_data); 101 + 94 102 } 95 103 96 104 public function testStorageTampering() {