Gin: How to read request header

Created on 10 Mar 2017  路  7Comments  路  Source: gin-gonic/gin

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.

question

Most helpful comment

c.Request.Header.Get("param")

All 7 comments

ctx.Request.Header

example:

    return func(c *gin.Context) {
        c.Writer.Header().Set("X-Revision", "v1.2.3")
        c.Next()
    }

Excuse me,
should we have a function like

c.GetHeader(key string) string

to easily get the value of specific request header with key ?

@FrozenKP

    if values, _ := c.Request.Header[key]; len(values) > 0 {
        return values[0]
    }
    return ""

hmmm... Can I write this as a function and pull request ? I think it would be useful.

@ponypaver @FrozenKP I add new func GetHeader in develop branch. see #839

c.Request.Header.Get("param")

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oryband picture oryband  路  3Comments

wangcn picture wangcn  路  3Comments

Bloomca picture Bloomca  路  3Comments

ccaza picture ccaza  路  3Comments

boneq picture boneq  路  3Comments