diff --git a/context.go b/context.go index b4f23952..f638e623 100644 --- a/context.go +++ b/context.go @@ -440,6 +440,11 @@ func (c *Context) Header(key, value string) { } } +// GetHeader returns value from request headers +func (c *Context) GetHeader(key string) string { + return c.requestHeader(key) +} + func (c *Context) SetCookie( name string, value string, diff --git a/context_test.go b/context_test.go index ebc5050e..52606281 100644 --- a/context_test.go +++ b/context_test.go @@ -1007,3 +1007,12 @@ func TestWebsocketsRequired(t *testing.T) { assert.False(t, c.IsWebsocket()) } + +func TestGetRequestHeaderValue(t *testing.T) { + c, _ := CreateTestContext(httptest.NewRecorder()) + c.Request, _ = http.NewRequest("GET", "/chat", nil) + c.Request.Header.Set("Gin-Version", "1.0.0") + + assert.Equal(t, "1.0.0", c.GetHeader("Gin-Version")) + assert.Equal(t, "", c.GetHeader("Connection")) +}