From 431e339ccc2acace4069c0ce3f14477782848f9e Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Tue, 6 Feb 2018 11:55:56 +0200 Subject: [PATCH] don't force-set content type on gzip response writer's WriteString and Writef if already there Former-commit-id: c882a6ef14e89dd0da7a3a2afc85100ca07dc869 --- Gopkg.lock | 2 +- context/gzip_response_writer.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index c77e0692..6bf5e157 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -170,7 +170,7 @@ revision = "abc90934186a77966e2beeac62ed966aac0561d5" [[projects]] - branch = "master" + branch = "v1.2.0" name = "github.com/satori/go.uuid" packages = ["."] revision = "f58768cc1a7a7e77a3bd49e98cdd21419399b6a3" diff --git a/context/gzip_response_writer.go b/context/gzip_response_writer.go index 05ee0c65..c9582f99 100644 --- a/context/gzip_response_writer.go +++ b/context/gzip_response_writer.go @@ -117,7 +117,9 @@ func (w *GzipResponseWriter) Write(contents []byte) (int, error) { func (w *GzipResponseWriter) Writef(format string, a ...interface{}) (n int, err error) { n, err = fmt.Fprintf(w, format, a...) if err == nil { - w.ResponseWriter.Header().Set(contentTypeHeaderKey, ContentTextHeaderValue) + if w.ResponseWriter.Header()[contentTypeHeaderKey] == nil { + w.ResponseWriter.Header().Set(contentTypeHeaderKey, ContentTextHeaderValue) + } } return @@ -128,7 +130,10 @@ func (w *GzipResponseWriter) Writef(format string, a ...interface{}) (n int, err func (w *GzipResponseWriter) WriteString(s string) (n int, err error) { n, err = w.Write([]byte(s)) if err == nil { - w.ResponseWriter.Header().Set(contentTypeHeaderKey, ContentTextHeaderValue) + if w.ResponseWriter.Header()[contentTypeHeaderKey] == nil { + w.ResponseWriter.Header().Set(contentTypeHeaderKey, ContentTextHeaderValue) + } + } return }