diff options
author | Frédéric Guillot <fred@miniflux.net> | 2018-07-19 19:27:05 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2018-07-19 19:27:05 -0700 |
commit | 9f6533ece90c6b528dd0af6f1b6dec4a7fa2fa3b (patch) | |
tree | 59349657a1d5a700abab38332d4e7240533ab4d3 /http/response/response.go | |
parent | a291d8a38b40569fdd1f00125ca0b29e4b9264f2 (diff) |
Compress JSON, CSS and Javascript responses
Diffstat (limited to 'http/response/response.go')
-rw-r--r-- | http/response/response.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/http/response/response.go b/http/response/response.go index c5ae3fa..f792625 100644 --- a/http/response/response.go +++ b/http/response/response.go @@ -23,7 +23,7 @@ func NotModified(w http.ResponseWriter) { } // Cache returns a response with caching headers. -func Cache(w http.ResponseWriter, r *http.Request, mimeType, etag string, content []byte, duration time.Duration) { +func Cache(w http.ResponseWriter, r *http.Request, mimeType, etag string, data []byte, duration time.Duration) { w.Header().Set("Content-Type", mimeType) w.Header().Set("ETag", etag) w.Header().Set("Cache-Control", "public") @@ -31,8 +31,14 @@ func Cache(w http.ResponseWriter, r *http.Request, mimeType, etag string, conten if etag == r.Header.Get("If-None-Match") { w.WriteHeader(http.StatusNotModified) - } else { - w.Write(content) + return + } + + switch mimeType { + case "text/javascript; charset=utf-8", "text/css; charset=utf-8": + Compress(w, r, data) + default: + w.Write(data) } } |