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) } }
func (j JSONP) Filter(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) { if req.Method() != "GET" { chain(req, resp) return } res, _ := req.ResourceMaster().Resource(resource.RES_JSON) if res == nil { resp.ReportNotAcceptable() return } callback := req.Param(string(j)) if callback == "" { resp.ReportBadRequest() resp.Send("error", "no callback function") return } resp.SetContentType(resource.RES_JSON, res) _, err := resp.WriteString(callback) if err != nil { goto ERROR } _, err = resp.WriteString("(") if err != nil { goto ERROR } chain(req, resp) _, err = resp.WriteString(")") if err == nil { return } ERROR: req.Logger().Warnln(err) }