func (h *RouteHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Create the context ctx, err := h.Server.NewContext(w, req) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } defer ctx.Close() // Run the handler and grab the error, and report it buf := new(httpbuf.Buffer) ctx.Writer = buf err = h.Handler(ctx) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } // Save the session if err = ctx.Session.Save(req, buf); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } // Apply the buffered response to the writer buf.Apply(w) }
func (h Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { w.Header().Set("Content-Encoding", "gzip") gzz := gzip.NewWriter(w) defer gzz.Close() gz := gzipResponseWriter{Writer: gzz, ResponseWriter: w} //create the context ctx, err := models.NewContext(req) if err != nil { internal_error(gz, req, "new context err: "+err.Error()) return } defer ctx.Close() //run the handler and grab the error, and report it buf := new(httpbuf.Buffer) err = h(buf, req, ctx) if err != nil { internal_error(gz, req, "buffer err: "+err.Error()) return } //save the session if err = ctx.Session.Save(req, buf); err != nil { internal_error(gz, req, "session save err: "+err.Error()) return } // set content type and length //buf.Header().Set("Content-Type", "text/html") //buf.Header().Set("Content-Length", string(buf.Len())) //apply the buffered response to the writer buf.Apply(gz) }
func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { //create the context ctx, err := NewContext(req) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } defer ctx.Close() //run the handler and grab the error, and report it buf := new(httpbuf.Buffer) err = h(buf, req, ctx) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } //save the session if err = ctx.Session.Save(req, buf); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } //apply the buffered response to the writer buf.Apply(w) }
func perform(r runner, w http.ResponseWriter, req *http.Request) { ctx := init_context(req) defer ctx.Close() var buf httpbuf.Buffer defer buf.Apply(w) r.Run(&buf, req, ctx) ctx.Save(req, w) }
func cached_main(w http.ResponseWriter, req *http.Request) { if buf, ex := app_cache.get(req.URL.Path); ex { buf.Apply(w) return } buf := new(httpbuf.Buffer) handle_main(buf, req) app_cache.set(req.URL.Path, buf) buf.Apply(w) }