aboutsummaryrefslogtreecommitdiff
path: root/lib/http/testdata
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-01-19 03:39:50 +0700
committerShulhan <ms@kilabit.info>2024-01-24 00:07:18 +0700
commiteb2b4dbdeceb663b1ce29bc08cd5446ecf4c1f07 (patch)
treecfeb884e2890d8f74c516eaad9e0bc7a8bbdce59 /lib/http/testdata
parentdbfc1583d77d300f8da8e2d3714fa1592dde09a0 (diff)
downloadpakakeh.go-eb2b4dbdeceb663b1ce29bc08cd5446ecf4c1f07.tar.xz
lib/http: refactoring Range request, limit content served by server
When server receive, GET /big Range: bytes=0- and the requested resources is quite larger, where writing all content of file result in i/o timeout, it is best practice [1][2] if the server write only partial content and let the client continue with the subsequent Range request. In the above case, the server should response with, HTTP/1.1 206 Partial content Content-Range: bytes 0-<limit>/<size> Content-Length: <limit> Where limit is maximum packet that is reasonable [3] for most of the client. In this server we choose 8MB as limit. [1]: https://stackoverflow.com/questions/63614008/how-best-to-respond-to-an-open-http-range-request [2]: https://bugzilla.mozilla.org/show_bug.cgi?id=570755 [3]: https://docs.aws.amazon.com/whitepapers/latest/s3-optimizing-performance-best-practices/use-byte-range-fetches.html
Diffstat (limited to 'lib/http/testdata')
-rw-r--r--lib/http/testdata/server/range/fail_416_test.txt1
-rw-r--r--lib/http/testdata/server/range/multipart_test.txt4
-rw-r--r--lib/http/testdata/server/range_big_test.txt14
3 files changed, 17 insertions, 2 deletions
diff --git a/lib/http/testdata/server/range/fail_416_test.txt b/lib/http/testdata/server/range/fail_416_test.txt
index 88b54d14..bac7bc87 100644
--- a/lib/http/testdata/server/range/fail_416_test.txt
+++ b/lib/http/testdata/server/range/fail_416_test.txt
@@ -4,6 +4,7 @@ bytes=50-
<<< http_headers
HTTP/1.1 416 Requested Range Not Satisfiable
Content-Length: 0
+Content-Range: bytes */40
Content-Type: text/html; charset=utf-8
<<< http_body
diff --git a/lib/http/testdata/server/range/multipart_test.txt b/lib/http/testdata/server/range/multipart_test.txt
index 0c1608ab..bb90ca95 100644
--- a/lib/http/testdata/server/range/multipart_test.txt
+++ b/lib/http/testdata/server/range/multipart_test.txt
@@ -3,7 +3,7 @@ bytes=0-5,10-15,-10
<<< http_headers
HTTP/1.1 206 Partial Content
-Content-Length: 325
+Content-Length: 327
Content-Type: multipart/byteranges; boundary=1b4df158039f7cce
<<< http_body
@@ -19,7 +19,7 @@ Content-Range: bytes 10-15/40
y>Hell
--1b4df158039f7cce
Content-Type: text/html; charset=utf-8
-Content-Range: bytes -10/40
+Content-Range: bytes 30-39/40
y></html>
diff --git a/lib/http/testdata/server/range_big_test.txt b/lib/http/testdata/server/range_big_test.txt
new file mode 100644
index 00000000..8d47b707
--- /dev/null
+++ b/lib/http/testdata/server/range_big_test.txt
@@ -0,0 +1,14 @@
+
+<<< HEAD /big
+HTTP/1.1 200 OK
+Accept-Ranges: bytes
+Content-Length: 10485760
+Content-Type: application/octet-stream
+Etag: 1704070861
+
+<<< GET /big:Range=0-
+HTTP/1.1 206 Partial Content
+Content-Length: 8388608
+Content-Range: bytes 0-8388608/10485760
+Content-Type: application/octet-stream
+Etag: 1704070861