From b9683af2da882d542208a15d67d8040bab8fa5c2 Mon Sep 17 00:00:00 2001 From: Billy Brown Date: Thu, 21 Dec 2023 17:07:00 +0000 Subject: Corrected Range and Content-Range header handling Corrected the handling of the Range request header and the Content- Range response header. They now have separate parsers, to match the standard, and the content-range unparser is now correctly named. The Range header can be in one of three forms: Range: bytes=- Range: bytes=- Range: bytes=- The Content-Range header can be in one of three forms: Content-Range: bytes -/ Content-Range: bytes -/* Content-Range: bytes */ The unit tests were updated to reflect the changes. Signed-off-by: Peter Bex --- tests/run.scm | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/run.scm b/tests/run.scm index d97f15d..95a3990 100644 --- a/tests/run.scm +++ b/tests/run.scm @@ -300,10 +300,34 @@ (header-value 'content-md5 headers)))) (test-group "range-parser" - (let ((headers (test-read-headers "content-range: bytes 500-999/1234"))) - (test "Simple range" - '(500 999 1234) - (header-value 'content-range headers)))) + (let ((headers (test-read-headers "range: bytes=500-999"))) + (test "Simple range full" + '(500 999) + (header-value 'range headers))) + (let ((headers (test-read-headers "range: bytes=500-"))) + (test "Simple range start" + '(500 #f) + (header-value 'range headers))) + (let ((headers (test-read-headers "range: bytes=-999"))) + (test "Simple range end" + '(#f 999) + (header-value 'range headers))) + (let ((headers (test-read-headers "range: bytes 500-999/1234"))) + (test "Content-range failure" + #f + (header-value 'range headers))) + (let ((headers (test-read-headers "range: bytes=-"))) + (test "Numberless range failure" + #f + (header-value 'range headers))) + (let ((headers (test-read-headers "range: bytes 500-999"))) + (test "Space failure" + #f + (header-value 'range headers))) + (let ((headers (test-read-headers "range: bits=500-999"))) + (test "Wrong units failure" + #f + (header-value 'range headers)))) (test-group "content-disposition" (let ((headers (test-read-headers "Content-Disposition: attachment; filename=dir/foo.jpg"))) @@ -645,6 +669,16 @@ (test-error* "Embedded newlines in raw headers also throw an error" (exn http unencoded-header) (test-unparse-headers `((foo #("bar\n\x01qux" raw)))))) + (test-group "content-range unparser" + (test "Full content-range" + "Content-Range: bytes 500-999/1234\r\n" + (test-unparse-headers `((content-range (500 999 1234))))) + (test "Wildcard size content-range" + "Content-Range: bytes 500-999/*\r\n" + (test-unparse-headers `((content-range (500 999 #f))))) + (test "Wildcard range content-range" + "Content-Range: bytes */1234\r\n" + (test-unparse-headers `((content-range (#f #f 1234)))))) (test-group "etag unparser" (test "Weak tag" "Etag: W/\"blah\"\r\n" -- cgit v1.2.3