diff options
| author | Shulhan <ms@kilabit.info> | 2023-03-11 15:51:03 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-03-12 11:35:19 +0700 |
| commit | 3c2f1c8044776eb68d9a1e2992eb37157b1018a6 (patch) | |
| tree | d44ee3cc08de58c17529db45e773c6686606c094 /lib/http/range_position_example_test.go | |
| parent | 61786b2a6c1a7c9d11ee18cab4a804afdce9ffa5 (diff) | |
| download | pakakeh.go-3c2f1c8044776eb68d9a1e2992eb37157b1018a6.tar.xz | |
lib/http: add support for HTTP Range in Server
For HTTP Server using HandleFS, the Range request is handled
automatically.
For other HTTP server, user can use the HandleRange function.
The HandleRange function handle [HTTP Range] request using "bytes" unit.
The body parameter contains the content of resource being requested that
accept Seek method.
If the Request method is not GET, or no Range in header request it will
return all the body [RFC7233 S-3.1].
The contentType is optional, if its empty, it will detected by
http.ResponseWriter during Write.
[HTTP Range]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests
[RFC7233 S-3.1]: https://datatracker.ietf.org/doc/html/rfc7233#section-3.1
# Conflicts:
# CHANGELOG.adoc
Diffstat (limited to 'lib/http/range_position_example_test.go')
| -rw-r--r-- | lib/http/range_position_example_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/http/range_position_example_test.go b/lib/http/range_position_example_test.go new file mode 100644 index 00000000..bedf4774 --- /dev/null +++ b/lib/http/range_position_example_test.go @@ -0,0 +1,23 @@ +package http_test + +import ( + "fmt" + + libhttp "github.com/shuLhan/share/lib/http" +) + +func ExampleRangePosition_ContentRange() { + var ( + unit = libhttp.AcceptRangesBytes + pos = libhttp.RangePosition{ + Start: 10, + End: 20, + } + ) + + fmt.Println(pos.ContentRange(unit, 512)) + fmt.Println(pos.ContentRange(unit, 0)) + // Output: + // bytes 10-20/512 + // bytes 10-20/* +} |
