summaryrefslogtreecommitdiff
path: root/system/api/handlers.go
diff options
context:
space:
mode:
Diffstat (limited to 'system/api/handlers.go')
-rw-r--r--system/api/handlers.go25
1 files changed, 22 insertions, 3 deletions
diff --git a/system/api/handlers.go b/system/api/handlers.go
index 9292e15..2e70fdc 100644
--- a/system/api/handlers.go
+++ b/system/api/handlers.go
@@ -129,7 +129,7 @@ func contentHandler(res http.ResponseWriter, req *http.Request) {
return
}
- defer push(res, req, pt, post)
+ push(res, req, pt, post)
j, err := fmtJSON(json.RawMessage(post))
if err != nil {
@@ -166,7 +166,7 @@ func contentHandlerBySlug(res http.ResponseWriter, req *http.Request) {
return
}
- defer push(res, req, it, post)
+ push(res, req, it, post)
j, err := fmtJSON(json.RawMessage(post))
if err != nil {
@@ -332,7 +332,12 @@ func Gzip(next http.HandlerFunc) http.HandlerFunc {
if strings.Contains(req.Header.Get("Accept-Encoding"), "gzip") {
// gzip response data
res.Header().Set("Content-Encoding", "gzip")
- gzres := gzipResponseWriter{res, gzip.NewWriter(res)}
+ var gzres gzipResponseWriter
+ if pusher, ok := res.(http.Pusher); ok {
+ gzres = gzipResponseWriter{res, pusher, gzip.NewWriter(res)}
+ } else {
+ gzres = gzipResponseWriter{res, nil, gzip.NewWriter(res)}
+ }
next.ServeHTTP(gzres, req)
return
@@ -344,6 +349,8 @@ func Gzip(next http.HandlerFunc) http.HandlerFunc {
type gzipResponseWriter struct {
http.ResponseWriter
+ pusher http.Pusher
+
gw *gzip.Writer
}
@@ -351,3 +358,15 @@ func (gzw gzipResponseWriter) Write(p []byte) (int, error) {
defer gzw.gw.Close()
return gzw.gw.Write(p)
}
+
+func (gzw gzipResponseWriter) Push(target string, opts *http.PushOptions) error {
+ if opts == nil {
+ opts = &http.PushOptions{
+ Header: make(http.Header),
+ }
+ }
+
+ opts.Header.Set("Accept-Encoding", "gzip")
+
+ return gzw.pusher.Push(target, opts)
+}