diff --git a/httpbin/handlers.go b/httpbin/handlers.go index f2b6629ab2562f35cf05515dcb41b83aec573b5a..17f0cdfe17d50401e89ad8791f01e3da9ffe5662 100644 --- a/httpbin/handlers.go +++ b/httpbin/handlers.go @@ -87,7 +87,6 @@ func (h *HTTPBin) Gzip(w http.ResponseWriter, r *http.Request) { gzBody := buf.Bytes() w.Header().Set("Content-Encoding", "gzip") - w.Header().Set("Content-Length", fmt.Sprintf("%d", len(gzBody))) writeJSON(w, gzBody, http.StatusOK) } @@ -108,7 +107,6 @@ func (h *HTTPBin) Deflate(w http.ResponseWriter, r *http.Request) { compressedBody := buf.Bytes() w.Header().Set("Content-Encoding", "deflate") - w.Header().Set("Content-Length", fmt.Sprintf("%d", len(compressedBody))) writeJSON(w, compressedBody, http.StatusOK) } diff --git a/httpbin/helpers.go b/httpbin/helpers.go index ccc08cc194a8a39d7d33783ebf763c64e9d15064..b857c8591fe3a3ef5ce00a31324859a4dc9b1ef6 100644 --- a/httpbin/helpers.go +++ b/httpbin/helpers.go @@ -2,6 +2,7 @@ package httpbin import ( "encoding/json" + "fmt" "io/ioutil" "net/http" "net/url" @@ -48,6 +49,7 @@ func getURL(r *http.Request) *url.URL { func writeJSON(w http.ResponseWriter, body []byte, status int) { w.Header().Set("Content-Type", jsonContentType) + w.Header().Set("Content-Length", fmt.Sprintf("%d", len(body))) w.WriteHeader(status) w.Write(body) }