From e9f906ce5682d43312055dd3faff77f6e39ac5be Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Fri, 29 Nov 2024 13:19:55 +0000 Subject: [PATCH] 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 --- app/Http/RangeSupportedStream.php | 2 +- tests/Uploads/AttachmentTest.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Http/RangeSupportedStream.php b/app/Http/RangeSupportedStream.php index 300f4488c..fce1e9acc 100644 --- a/app/Http/RangeSupportedStream.php +++ b/app/Http/RangeSupportedStream.php @@ -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; diff --git a/tests/Uploads/AttachmentTest.php b/tests/Uploads/AttachmentTest.php index 2e1a7b339..de448d93a 100644 --- a/tests/Uploads/AttachmentTest.php +++ b/tests/Uploads/AttachmentTest.php @@ -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();