aboutsummaryrefslogtreecommitdiff
path: root/lib/http/range_position_example_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-03-11 20:16:59 +0700
committerShulhan <ms@kilabit.info>2023-03-12 11:37:17 +0700
commit7d4c26cef490689eb5817c17e102d1e7128c682e (patch)
treeb69ea23471932b0a8054bb1a371f8b21a156361c /lib/http/range_position_example_test.go
parent8e2fa2b18662da4e42bc2be5f20103dd5e2cb8f8 (diff)
downloadpakakeh.go-7d4c26cef490689eb5817c17e102d1e7128c682e.tar.xz
lib/http: add function to parse multipart Range response for Client
The ParseMultipartRange parse the multipart/byteranges body or response from HTTP Range request. Each Content-Range position and body part in the multipart will be stored under RangePosition.
Diffstat (limited to 'lib/http/range_position_example_test.go')
-rw-r--r--lib/http/range_position_example_test.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/http/range_position_example_test.go b/lib/http/range_position_example_test.go
index bedf4774..927a6627 100644
--- a/lib/http/range_position_example_test.go
+++ b/lib/http/range_position_example_test.go
@@ -6,6 +6,24 @@ import (
libhttp "github.com/shuLhan/share/lib/http"
)
+func ExampleParseContentRange() {
+ fmt.Println(libhttp.ParseContentRange(`bytes 10-/20`)) // OK
+ fmt.Println(libhttp.ParseContentRange(`bytes 10-19/20`)) // OK
+ fmt.Println(libhttp.ParseContentRange(`bytes -10/20`)) // OK
+ fmt.Println(libhttp.ParseContentRange(`10-20/20`)) // Invalid, missing unit.
+ fmt.Println(libhttp.ParseContentRange(`bytes 10-`)) // Invalid, missing "/size".
+ fmt.Println(libhttp.ParseContentRange(`bytes -10/x`)) // Invalid, invalid "size".
+ fmt.Println(libhttp.ParseContentRange(`bytes`)) // Invalid, missing position.
+ // Output:
+ // 10-
+ // 10-19
+ // -10
+ // <nil>
+ // <nil>
+ // <nil>
+ // <nil>
+}
+
func ExampleRangePosition_ContentRange() {
var (
unit = libhttp.AcceptRangesBytes