From 16f32db977c735c27289d98f2ef121025a2f1f72 Mon Sep 17 00:00:00 2001 From: Paul Mundt Date: Sun, 3 Apr 2016 11:01:36 +0200 Subject: Fix up gzip error handling In the case where the server has enabled gzip support but it is not supported by the requesting client, the error path serves up the uncompressed response but then fails to return immediately, resulting in the compressed response being written out also. --- src/dict2rest/gzip.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dict2rest/gzip.go b/src/dict2rest/gzip.go index 15f550f..d2264e2 100644 --- a/src/dict2rest/gzip.go +++ b/src/dict2rest/gzip.go @@ -20,7 +20,9 @@ func (w gzipResponseWriter) Write(b []byte) (int, error) { func Gzip(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { if !strings.Contains(req.Header.Get("Accept-Encoding"), "gzip") { + // If gzip is unsupported, revert to standard handler. next.ServeHTTP(w, req) + return } w.Header().Set("Content-Encoding", "gzip") gz := gzip.NewWriter(w) -- cgit v1.2.3