mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-16 17:47:52 +00:00
Attachments: Fixed full range request handling
We were not responsing with a range request, where the requested range was for the full extent of content. This changes things to always provide a range request, even for the full range. Change made since our existing logic could cause problems in chromium browsers. Elseif statement removed as its was likley redundant based upon other existing checks. This also changes responses for requested ranges beyond content, but I think that's technically correct looking at the spec (416 are for when there are no overlapping request/response ranges at all). Updated tests to cover. For #5342
This commit is contained in:
parent
4630f07282
commit
e9f906ce56
2 changed files with 10 additions and 3 deletions
|
@ -92,7 +92,7 @@ class RangeSupportedStream
|
|||
if ($start < 0 || $start > $end) {
|
||||
$this->responseStatus = 416;
|
||||
$this->responseHeaders['Content-Range'] = sprintf('bytes */%s', $this->fileSize);
|
||||
} elseif ($end - $start < $this->fileSize - 1) {
|
||||
} else {
|
||||
$this->responseLength = $end < $this->fileSize ? $end - $start + 1 : -1;
|
||||
$this->responseOffset = $start;
|
||||
$this->responseStatus = 206;
|
||||
|
|
|
@ -404,8 +404,8 @@ class AttachmentTest extends TestCase
|
|||
$resp = $this->get($attachment->getUrl($isInline), ['Range' => 'bytes=0-2010']);
|
||||
$resp->assertStreamedContent($content);
|
||||
$resp->assertHeader('Content-Length', '2005');
|
||||
$resp->assertHeaderMissing('Content-Range');
|
||||
$resp->assertStatus(200);
|
||||
$resp->assertHeader('Content-Range', 'bytes 0-2004/2005');
|
||||
$resp->assertStatus(206);
|
||||
|
||||
// Range start before end
|
||||
$resp = $this->get($attachment->getUrl($isInline), ['Range' => 'bytes=50-10']);
|
||||
|
@ -413,6 +413,13 @@ class AttachmentTest extends TestCase
|
|||
$resp->assertHeader('Content-Length', '2005');
|
||||
$resp->assertHeader('Content-Range', 'bytes */2005');
|
||||
$resp->assertStatus(416);
|
||||
|
||||
// Full range request
|
||||
$resp = $this->get($attachment->getUrl($isInline), ['Range' => 'bytes=0-']);
|
||||
$resp->assertStreamedContent($content);
|
||||
$resp->assertHeader('Content-Length', '2005');
|
||||
$resp->assertHeader('Content-Range', 'bytes 0-2004/2005');
|
||||
$resp->assertStatus(206);
|
||||
}
|
||||
|
||||
$this->files->deleteAllAttachmentFiles();
|
||||
|
|
Loading…
Add table
Reference in a new issue