Hi Guys,
May I know how to read the request header from gin context ? It seems there is only a write header function in the document.
Thanks in advance.
Comment From: lixiangzhong
ctx.Request.Header
Comment From: appleboy
example:
return func(c *gin.Context) {
c.Writer.Header().Set("X-Revision", "v1.2.3")
c.Next()
}
Comment From: frozenkp
Excuse me, should we have a function like
c.GetHeader(key string) string
to easily get the value of specific request header with key ?
Comment From: appleboy
@FrozenKP
if values, _ := c.Request.Header[key]; len(values) > 0 {
return values[0]
}
return ""
Comment From: frozenkp
hmmm... Can I write this as a function and pull request ? I think it would be useful.
Comment From: appleboy
@ponypaver @FrozenKP I add new func GetHeader
in develop branch. see #839
Comment From: viethocle
c.Request.Header.Get("param")
Comment From: eloyekunle
c.GetHeader("param")
is much simpler