feat: Support get value from request header. (#839)
This commit is contained in:
parent
6bdc9afc8f
commit
ad2dacedd6
@ -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,
|
||||
|
@ -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"))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user