本文整理匯總了Golang中github.com/cosiner/zerver.Response.Wrap方法的典型用法代碼示例。如果您正苦於以下問題:Golang Response.Wrap方法的具體用法?Golang Response.Wrap怎麽用?Golang Response.Wrap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cosiner/zerver.Response
的用法示例。
在下文中一共展示了Response.Wrap方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Compress
func Compress(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) {
encoding := req.AcceptEncodings()
if strings.Contains(encoding, zerver.ENCODING_GZIP) {
resp.SetContentEncoding(zerver.ENCODING_GZIP)
resp.Wrap(gzipWrapper)
} else if strings.Contains(encoding, zerver.ENCODING_DEFLATE) {
resp.SetContentEncoding(zerver.ENCODING_DEFLATE)
resp.Wrap(flateWrapper)
} else {
chain(req, resp)
return
}
chain(req, resp)
resp.RemoveHeader("Content-Length")
}
示例2: Compress
func Compress(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) {
encoding := req.GetHeader(zerver.HEADER_ACCEPTENCODING)
respHeaders := resp.Headers()
if strings.Contains(encoding, zerver.ENCODING_GZIP) {
respHeaders.Set(zerver.HEADER_CONTENTENCODING, zerver.ENCODING_GZIP)
resp.Wrap(gzipWrapper)
} else if strings.Contains(encoding, zerver.ENCODING_DEFLATE) {
respHeaders.Set(zerver.HEADER_CONTENTENCODING, zerver.ENCODING_DEFLATE)
resp.Wrap(flateWrapper)
} else {
chain(req, resp)
return
}
chain(req, resp)
respHeaders.Del(zerver.HEADER_CONTENTLENGTH)
}
示例3: Filter
func (j *JSONP) Filter(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) {
if req.ReqMethod() != zerver.METHOD_GET {
chain(req, resp)
return
}
callback := req.Vars().QueryVar(j.CallbackVar)
if callback == "" {
chain(req, resp)
return
}
buffer := bytes.NewBuffer(make([]byte, 0, 256))
bw := wrap.BuffRespWriter{ // to avoid write header 200 first when write callback name
Buffer: buffer,
}
resp.Wrap(func(w http.ResponseWriter, shouldClose bool) (http.ResponseWriter, bool) {
bw.ResponseWriter = w
bw.ShouldClose = shouldClose
return &bw, shouldClose
})
chain(req, resp)
bw.Buffer = nil
_, err := io2.WriteString(resp, callback)
if err == nil {
_, err = io2.WriteString(resp, "(")
if err == nil {
_, err = resp.Write(buffer.Bytes())
if err == nil {
_, err = io2.WriteString(resp, ")")
}
}
}
if err != nil {
j.log.Warn(log.M{"msg": "write jsonp response failed", "err": err.Error()})
}
}