func (r *Recovery) Filter(req zerver.Request, resp zerver.Response, chain zerver.FilterChain) { defer func() { e := recover() if e == nil || r.NoStack { return } resp.ReportInternalServerError() buffer := bytes.NewBuffer(make([]byte, 0, r.Bufsize)) fmt.Fprint(buffer, e) buf := buffer.Bytes() runtime.Stack(buf[len(buf):cap(buf)], false) req.Logger().Errorln(unsafe2.String(buf[:cap(buf)])) }() 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) }