Skip to content

Commit e9f906c

Browse files
committed
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
1 parent 4630f07 commit e9f906c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

app/Http/RangeSupportedStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function parseRequest(Request $request): void
9292
if ($start < 0 || $start > $end) {
9393
$this->responseStatus = 416;
9494
$this->responseHeaders['Content-Range'] = sprintf('bytes */%s', $this->fileSize);
95-
} elseif ($end - $start < $this->fileSize - 1) {
95+
} else {
9696
$this->responseLength = $end < $this->fileSize ? $end - $start + 1 : -1;
9797
$this->responseOffset = $start;
9898
$this->responseStatus = 206;

tests/Uploads/AttachmentTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,22 @@ public function test_file_head_range_edge_cases()
404404
$resp = $this->get($attachment->getUrl($isInline), ['Range' => 'bytes=0-2010']);
405405
$resp->assertStreamedContent($content);
406406
$resp->assertHeader('Content-Length', '2005');
407-
$resp->assertHeaderMissing('Content-Range');
408-
$resp->assertStatus(200);
407+
$resp->assertHeader('Content-Range', 'bytes 0-2004/2005');
408+
$resp->assertStatus(206);
409409

410410
// Range start before end
411411
$resp = $this->get($attachment->getUrl($isInline), ['Range' => 'bytes=50-10']);
412412
$resp->assertStreamedContent($content);
413413
$resp->assertHeader('Content-Length', '2005');
414414
$resp->assertHeader('Content-Range', 'bytes */2005');
415415
$resp->assertStatus(416);
416+
417+
// Full range request
418+
$resp = $this->get($attachment->getUrl($isInline), ['Range' => 'bytes=0-']);
419+
$resp->assertStreamedContent($content);
420+
$resp->assertHeader('Content-Length', '2005');
421+
$resp->assertHeader('Content-Range', 'bytes 0-2004/2005');
422+
$resp->assertStatus(206);
416423
}
417424

418425
$this->files->deleteAllAttachmentFiles();

0 commit comments

Comments
 (0)