From 9795e59c435b0bbd992d5dda6b6904839e3b6bcc Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Wed, 16 Mar 2016 16:27:31 -0700 Subject: [PATCH] Closes #411 Signed-off-by: Vishal Rana --- engine/engine.go | 1 + engine/fasthttp/header.go | 22 ++++++++++++++++++++++ engine/standard/header.go | 11 +++++++++++ test/header.go | 10 ++++++++++ 4 files changed, 44 insertions(+) diff --git a/engine/engine.go b/engine/engine.go index d3f410a1..2157f6c5 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -57,6 +57,7 @@ type ( Del(string) Set(string, string) Get(string) string + Keys() []string } // URL defines the interface for HTTP request url. diff --git a/engine/fasthttp/header.go b/engine/fasthttp/header.go index 36417102..e3dfdbc1 100644 --- a/engine/fasthttp/header.go +++ b/engine/fasthttp/header.go @@ -36,6 +36,17 @@ func (h *RequestHeader) Get(key string) string { return string(h.Peek(key)) } +// Keys implements `engine.Header#Keys` method. +func (h *RequestHeader) Keys() (keys []string) { + keys = make([]string, h.Len()) + i := 0 + h.VisitAll(func(k, v []byte) { + keys[i] = string(k) + i++ + }) + return +} + func (h *RequestHeader) reset(hdr *fasthttp.RequestHeader) { h.RequestHeader = hdr } @@ -61,6 +72,17 @@ func (h *ResponseHeader) Set(key, val string) { h.ResponseHeader.Set(key, val) } +// Keys implements `engine.Header#Keys` method. +func (h *ResponseHeader) Keys() (keys []string) { + keys = make([]string, h.Len()) + i := 0 + h.VisitAll(func(k, v []byte) { + keys[i] = string(k) + i++ + }) + return +} + func (h *ResponseHeader) reset(hdr *fasthttp.ResponseHeader) { h.ResponseHeader = hdr } diff --git a/engine/standard/header.go b/engine/standard/header.go index 32622477..962094dd 100644 --- a/engine/standard/header.go +++ b/engine/standard/header.go @@ -29,6 +29,17 @@ func (h *Header) Get(key string) string { return h.Header.Get(key) } +// Keys implements `engine.Header#Keys` method. +func (h *Header) Keys() (keys []string) { + keys = make([]string, len(h.Header)) + i := 0 + for k := range h.Header { + keys[i] = k + i++ + } + return +} + func (h *Header) reset(hdr http.Header) { h.Header = hdr } diff --git a/test/header.go b/test/header.go index 18a1cdc8..cc41fe2c 100644 --- a/test/header.go +++ b/test/header.go @@ -24,6 +24,16 @@ func (h *Header) Set(key, val string) { h.header.Set(key, val) } +func (h *Header) Keys() (keys []string) { + keys = make([]string, len(h.header)) + i := 0 + for k := range h.header { + keys[i] = k + i++ + } + return +} + func (h *Header) reset(hdr http.Header) { h.header = hdr }