aboutsummaryrefslogtreecommitdiff
path: root/header.go
diff options
context:
space:
mode:
authorGravatar kinggo <lilong.21@bytedance.com> 2022-10-30 00:57:40 +0800
committerGravatar GitHub <noreply@github.com> 2022-10-29 18:57:40 +0200
commit3963a79a64ac0c35c38274516cdc1080a326102a (patch)
treeab2b399bbcff5125e1e2d4d9479ae19842457c1d /header.go
parentfix: (#1410) (diff)
downloadfasthttp-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.go52
1 files changed, 51 insertions, 1 deletions
diff --git a/header.go b/header.go
index 89499a3..fe4f669 100644
--- a/header.go
+++ b/header.go
@@ -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()