本文整理匯總了Golang中github.com/cosiner/zerver.Request.Header方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.Header方法的具體用法?Golang Request.Header怎麽用?Golang Request.Header使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cosiner/zerver.Request
的用法示例。
在下文中一共展示了Request.Header方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Filter
func (ri *RequestId) Filter(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) {
if req.Method() == "GET" {
chain(req, resp)
return
}
reqId := req.Header(ri.HeaderName)
if reqId == "" {
if ri.PassingOnNoId {
chain(req, resp)
} else {
resp.ReportBadRequest()
resp.Send("error", ri.Error)
}
} else {
id := req.RemoteIP() + ":" + reqId
if err := ri.Store.Save(id); err == ErrRequestIDExist {
resp.ReportForbidden()
resp.Send("error", ri.ErrorOverlap)
} else if err != nil {
ri.logger.Warnln(err)
} else {
chain(req, resp)
ri.Store.Remove(id)
}
}
}
示例2: VerifyFor
func (x *Xsrf) VerifyFor(req zerver.Request) bool {
m := req.Method()
if !x.FilterGet && (m == "GET" || m == "HEAD" || m == "OPTIONS") {
return true
}
token := req.Header(_HEADER_XSRFTOKEN)
if token == "" {
token = req.Header(_HEADER_CSRFTOKEN)
if token == "" {
token = req.Param(_XSRF_PARAM_NAME)
if token == "" {
return false
}
}
}
data := x.verify(unsafe2.Bytes(token))
if data != nil {
x.Pool.Put(data)
t, ip, agent := x.TokenInfo.Unmarshal(data)
return t != -1 &&
t+x.Timeout >= time2.Now().Unix() &&
ip == req.RemoteIP() &&
agent == req.UserAgent()
}
return false
}
示例3: Filter
func (c *CORS) Filter(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) {
reqMethod := req.Header(_CORS_REQUESTMETHOD)
reqHeaders := req.Header(_CORS_REQUESTHEADERS)
if req.Method() == "OPTIONS" && (reqMethod != "" || reqHeaders != "") {
c.preflight(req, resp, reqMethod, reqHeaders)
} else {
c.filter(req, resp, chain)
}
}
示例4: preflight
func (c *CORS) preflight(req zerver.Request, resp zerver.Response, method, headers string) {
origin := "*"
if !c.allowAll {
origin = req.Header(_CORS_ORIGIN)
if !c.allow(origin) {
resp.ReportOK()
return
}
}
resp.SetHeader(_CORS_ALLOWORIGIN, origin)
upperMethod := strings.ToUpper(method)
for _, m := range c.Methods {
if m == upperMethod {
resp.AddHeader(_CORS_ALLOWMETHODS, method)
break
}
}
for _, h := range strings2.SplitAndTrim(headers, ",") {
for _, ch := range c.Headers {
if strings.ToLower(h) == ch { // c.Headers already ToLowered when Init
resp.AddHeader(_CORS_ALLOWHEADERS, ch)
break
}
}
}
resp.SetHeader(_CORS_ALLOWCREDENTIALS, c.allowCredentials)
if c.exposeHeaders != "" {
resp.SetHeader(_CORS_EXPOSEHEADERS, c.exposeHeaders)
}
if c.preflightMaxage != "" {
resp.SetHeader(_CORS_MAXAGE, c.preflightMaxage)
}
resp.ReportOK()
}
示例5: filter
func (c *CORS) filter(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) {
origin := "*"
if !c.allowAll {
origin = req.Header(_CORS_ORIGIN)
if !c.allow(origin) {
resp.ReportForbidden()
return
}
}
resp.SetHeader(_CORS_ALLOWORIGIN, origin)
resp.SetHeader(_CORS_ALLOWMETHODS, c.methods)
resp.SetHeader(_CORS_ALLOWHEADERS, c.headers)
resp.SetHeader(_CORS_ALLOWCREDENTIALS, c.allowCredentials)
if c.exposeHeaders != "" {
resp.SetHeader(_CORS_EXPOSEHEADERS, c.exposeHeaders)
}
if c.preflightMaxage != "" {
resp.SetHeader(_CORS_MAXAGE, c.preflightMaxage)
}
chain(req, resp)
}