diff --git a/context.go b/context.go index afb6cc9..5d7d2d0 100644 --- a/context.go +++ b/context.go @@ -230,6 +230,14 @@ func (c *Context) AddHeader(key, value string) { c.Headers.Add(key, value) } +// ResetHeader reset response header +func (c *Context) ResetHeader() { + h := c.Header() + for k := range h { + h.Del(k) + } +} + // Cookie get cookie from http request func (c *Context) Cookie(name string) (*http.Cookie, error) { return c.Request.Cookie(name) diff --git a/context_test.go b/context_test.go index 65a9f51..af69d5e 100644 --- a/context_test.go +++ b/context_test.go @@ -209,6 +209,13 @@ func TestGetSetHeader(t *testing.T) { t.Fatalf("header function fail") } }) + + t.Run("reset header", func(t *testing.T) { + c.ResetHeader() + if len(c.Header()) != 0 { + t.Fatalf("reset header fail") + } + }) } func TestCookie(t *testing.T) {