本文整理汇总了Golang中github.com/zaolab/sunnified/web.Context.ReqHeaderHas方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.ReqHeaderHas方法的具体用法?Golang Context.ReqHeaderHas怎么用?Golang Context.ReqHeaderHas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/zaolab/sunnified/web.Context
的用法示例。
在下文中一共展示了Context.ReqHeaderHas方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Publish
func (this *HtmlView) Publish(ctxt *web.Context) (err error) {
names := mvc.GetMvcMeta(ctxt)
if names[mvc.MVC_ACTION] == "" {
names[mvc.MVC_ACTION] = "_"
}
var tmpl *template.Template
tmpl, err = this.getTmpl(names)
if err == nil {
var method = ctxt.Method()
ctxt.SetHeader("Content-Type", "text/html; charset=utf-8")
if method != "HEAD" {
var err error
var tw io.Writer = ctxt.Response
var gzipwriter *gzip.Writer
if ctxt.ReqHeaderHas("Accept-Encoding", "gzip") {
ctxt.SetHeader("Content-Encoding", "gzip")
gzipwriter, _ = gzip.NewWriterLevel(ctxt.Response, gzip.BestSpeed)
tw = gzipwriter
}
ctxt.SetHeader("Vary", "Accept-Encoding")
ctxt.Response.WriteHeader(200)
err = tmpl.Execute(tw, this.VM)
if err != nil {
// Header already sent... multiple write headers
//panic(err)
log.Println(err)
}
if gzipwriter != nil {
gzipwriter.Close()
}
if flushw, ok := ctxt.Response.(http.Flusher); ok {
flushw.Flush()
}
} else {
ctxt.Response.WriteHeader(200)
}
} else {
log.Println(err)
ctxt.SetErrorCode(500)
}
return
}
示例2: Publish
func (this *ResultView) Publish(ctxt *web.Context) (err error) {
names := mvc.GetMvcMeta(ctxt)
if names[mvc.MVC_ACTION] == "" {
names[mvc.MVC_ACTION] = "_"
}
var tmpl *template.Template
var ext string
/*
var mc = memcache.New("127.0.0.1:11211")
var item *memcache.Item
if item, err = mc.Get(ctxt.Request.RequestURI); err == nil {
ctxt.SetHeader("Content-Type", GetContentType(ext))
if ctxt.ReqHeaderHas("Accept-Encoding", "gzip") {
ctxt.SetHeader("Content-Encoding", "gzip")
}
ctxt.Response.Write(item.Value)
return
}
*/
tmpl, ext, err = this.getTmpl(names)
if err == nil {
var isjsonp bool
var jsonp string
var method = ctxt.Method()
if ext == ".jsonp" {
jsonp = ctxt.RequestValue("callback")
if jsonp == "" {
jsonp = ctxt.RequestValue("jsonp")
}
if (method == "GET" || method == "HEAD") && jsonp != "" && ext == ".jsonp" && validate.IsJSONPCallback(jsonp) {
ctxt.SetHeader("Content-Type", "application/javascript")
ctxt.SetHeader("Content-Disposition", "attachment; filename=jsonp.jsonp")
ctxt.SetHeader("X-Content-Type-Options", "nosniff")
isjsonp = true
} else {
err = errors.New("Invalid jsonp callback")
log.Println(err)
ctxt.SetErrorCode(403)
return
}
} else {
ctxt.SetHeader("Content-Type", GetContentType(ext))
}
if method != "HEAD" {
var err error
var b *bytes.Buffer = bytes.NewBuffer(make([]byte, 0, 5120))
var tw io.Writer = io.MultiWriter(ctxt.Response, b)
var gzipwriter *gzip.Writer
if ctxt.ReqHeaderHas("Accept-Encoding", "gzip") {
ctxt.SetHeader("Content-Encoding", "gzip")
gzipwriter, _ = gzip.NewWriterLevel(tw, gzip.BestSpeed)
tw = gzipwriter
}
ctxt.SetHeader("Vary", "Accept-Encoding")
ctxt.Response.WriteHeader(200)
if isjsonp {
writeJsonpStart(jsonp, tw)
}
err = tmpl.Execute(tw, this.VM)
if err != nil {
// Header already sent... multiple write headers
//panic(err)
log.Println(err)
}
if isjsonp {
writeJsonpEnd(jsonp, tw)
}
if gzipwriter != nil {
gzipwriter.Close()
}
//mc.Set(&memcache.Item{Key: ctxt.Request.RequestURI, Value: b.Bytes(), Expiration: 3600})
if flushw, ok := ctxt.RootResponse().(http.Flusher); ok {
flushw.Flush()
}
} else {
ctxt.Response.WriteHeader(200)
}
} else {
log.Println(err)
ctxt.SetErrorCode(500)
}
return
}