diff options
author | kinggo <lilong.21@bytedance.com> | 2022-10-30 00:57:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-29 18:57:40 +0200 |
commit | 3963a79a64ac0c35c38274516cdc1080a326102a (patch) | |
tree | ab2b399bbcff5125e1e2d4d9479ae19842457c1d /header.go | |
parent | fix: (#1410) (diff) | |
download | fasthttp-3963a79a64ac0c35c38274516cdc1080a326102a.tar.gz fasthttp-3963a79a64ac0c35c38274516cdc1080a326102a.tar.bz2 fasthttp-3963a79a64ac0c35c38274516cdc1080a326102a.zip |
feat: add PeekKeys and PeekTrailerKeys (#1405)
* feat: add PeekKeys and PeekTrailerKeys
* Improve warning
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
Diffstat (limited to 'header.go')
-rw-r--r-- | header.go | 52 |
1 files changed, 51 insertions, 1 deletions
@@ -1801,6 +1801,7 @@ func (h *RequestHeader) peek(key []byte) []byte { // // The returned value is valid until the request is released, // either though ReleaseRequest or your request handler returning. +// Any future calls to the Peek* will modify the returned value. // Do not store references to returned value. Make copies instead. func (h *RequestHeader) PeekAll(key string) [][]byte { k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) @@ -1847,7 +1848,8 @@ func (h *RequestHeader) peekAll(key []byte) [][]byte { // PeekAll returns all header value for the given key. // // The returned value is valid until the request is released, -// either though ReleaseRequest or your request handler returning. +// either though ReleaseResponse or your request handler returning. +// Any future calls to the Peek* will modify the returned value. // Do not store references to returned value. Make copies instead. func (h *ResponseHeader) PeekAll(key string) [][]byte { k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing) @@ -1887,6 +1889,54 @@ func (h *ResponseHeader) peekAll(key []byte) [][]byte { return h.mulHeader } +// PeekKeys return all header keys. +// +// The returned value is valid until the request is released, +// either though ReleaseRequest or your request handler returning. +// Any future calls to the Peek* will modify the returned value. +// Do not store references to returned value. Make copies instead. +func (h *RequestHeader) PeekKeys() [][]byte { + h.mulHeader = h.mulHeader[:0] + h.mulHeader = peekArgsKeys(h.mulHeader, h.h) + return h.mulHeader +} + +// PeekTrailerKeys return all trailer keys. +// +// The returned value is valid until the request is released, +// either though ReleaseRequest or your request handler returning. +// Any future calls to the Peek* will modify the returned value. +// Do not store references to returned value. Make copies instead. +func (h *RequestHeader) PeekTrailerKeys() [][]byte { + h.mulHeader = h.mulHeader[:0] + h.mulHeader = peekArgsKeys(h.mulHeader, h.trailer) + return h.mulHeader +} + +// PeekKeys return all header keys. +// +// The returned value is valid until the request is released, +// either though ReleaseResponse or your request handler returning. +// Any future calls to the Peek* will modify the returned value. +// Do not store references to returned value. Make copies instead. +func (h *ResponseHeader) PeekKeys() [][]byte { + h.mulHeader = h.mulHeader[:0] + h.mulHeader = peekArgsKeys(h.mulHeader, h.h) + return h.mulHeader +} + +// PeekTrailerKeys return all trailer keys. +// +// The returned value is valid until the request is released, +// either though ReleaseResponse or your request handler returning. +// Any future calls to the Peek* will modify the returned value. +// Do not store references to returned value. Make copies instead. +func (h *ResponseHeader) PeekTrailerKeys() [][]byte { + h.mulHeader = h.mulHeader[:0] + h.mulHeader = peekArgsKeys(h.mulHeader, h.trailer) + return h.mulHeader +} + // Cookie returns cookie for the given key. func (h *RequestHeader) Cookie(key string) []byte { h.collectCookies() |