feat: Support get value from request header. (#839)

This commit is contained in:
Bo-Yi Wu 2017-03-24 20:43:23 +08:00 committed by GitHub
parent 6bdc9afc8f
commit ad2dacedd6
2 changed files with 14 additions and 0 deletions

View File

@ -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,

View File

@ -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"))
}