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 }