aboutsummaryrefslogtreecommitdiff
path: root/header.go
diff options
context:
space:
mode:
authorGravatar byene0923 <34917110+byene0923@users.noreply.github.com> 2022-10-30 16:48:46 +0800
committerGravatar GitHub <noreply@github.com> 2022-10-30 09:48:46 +0100
commita468a7dd3734d9866ef6ab8ee1e36695f5c3b09c (patch)
tree0527f64b11e07d2841a25c073f1d8e2e0dbebb55 /header.go
parentfeat: add PeekKeys and PeekTrailerKeys (#1405) (diff)
downloadfasthttp-a468a7dd3734d9866ef6ab8ee1e36695f5c3b09c.tar.gz
fasthttp-a468a7dd3734d9866ef6ab8ee1e36695f5c3b09c.tar.bz2
fasthttp-a468a7dd3734d9866ef6ab8ee1e36695f5c3b09c.zip
feat: support mulit/range (#1398)
* feat: support mulit/range * fix: 1. lint code 2. add SetByteRanges method * fix: reduce the test number of testFSSingleByteRange
Diffstat (limited to 'header.go')
-rw-r--r--header.go27
1 files changed, 18 insertions, 9 deletions
diff --git a/header.go b/header.go
index fe4f669..8292767 100644
--- a/header.go
+++ b/header.go
@@ -113,24 +113,33 @@ func (h *ResponseHeader) SetContentRange(startPos, endPos, contentLength int) {
//
// - If startPos is negative, then 'bytes=-startPos' value is set.
// - If endPos is negative, then 'bytes=startPos-' value is set.
-func (h *RequestHeader) SetByteRange(startPos, endPos int) {
+func (h *RequestHeader) SetByteRanges(startPos, endPos []int) {
b := h.bufKV.value[:0]
b = append(b, strBytes...)
b = append(b, '=')
- if startPos >= 0 {
- b = AppendUint(b, startPos)
- } else {
- endPos = -startPos
- }
- b = append(b, '-')
- if endPos >= 0 {
- b = AppendUint(b, endPos)
+ for i := range startPos {
+ if i > 0 {
+ b = append(b, ',')
+ }
+ if startPos[i] >= 0 {
+ b = AppendUint(b, startPos[i])
+ } else {
+ endPos[i] = -startPos[i]
+ }
+ b = append(b, '-')
+ if endPos[i] >= 0 {
+ b = AppendUint(b, endPos[i])
+ }
}
h.bufKV.value = b
h.setNonSpecial(strRange, h.bufKV.value)
}
+func (h *RequestHeader) SetByteRange(startPos, endPos int) {
+ h.SetByteRanges([]int{startPos}, []int{endPos})
+}
+
// StatusCode returns response status code.
func (h *ResponseHeader) StatusCode() int {
if h.statusCode == 0 {