本文整理汇总了Golang中github.com/cosiner/zerver.Response.SetHeader方法的典型用法代码示例。如果您正苦于以下问题:Golang Response.SetHeader方法的具体用法?Golang Response.SetHeader怎么用?Golang Response.SetHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cosiner/zerver.Response
的用法示例。
在下文中一共展示了Response.SetHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: globalFilter
func globalFilter(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) {
resp.SetContentType("text/plain", nil)
if resp.Status() == http.StatusNotFound {
resp.SetHeader("Location", path+"/options?from="+url.QueryEscape(req.URL().Path))
resp.ReportMovedPermanently()
} else if resp.Status() == http.StatusMethodNotAllowed {
resp.WriteString("The pprof interface only support GET request\n")
} else {
chain(req, resp)
}
}
示例2: 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)
}
示例3: 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()
}