summaryrefslogtreecommitdiffhomepage
path: root/middleware/gzip
diff options
context:
space:
mode:
authorMatthew Holt <[email protected]>2015-05-02 09:20:39 -0600
committerMatthew Holt <[email protected]>2015-05-02 09:20:39 -0600
commitca95b561dc74f6b553c2b4f5237a04b15959f3ca (patch)
tree08355d2d3ddcc926e075597888dae15881886bd2 /middleware/gzip
parent9df9ad975d53db20f665787bd7c41a4ae4b094e1 (diff)
downloadcaddy-ca95b561dc74f6b553c2b4f5237a04b15959f3ca.tar.gz
caddy-ca95b561dc74f6b553c2b4f5237a04b15959f3ca.zip
gzip: Fix Content-Length header for proxies requests (closes #38)
Diffstat (limited to 'middleware/gzip')
-rw-r--r--middleware/gzip/gzip.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/middleware/gzip/gzip.go b/middleware/gzip/gzip.go
index 694118321..8bbc1d146 100644
--- a/middleware/gzip/gzip.go
+++ b/middleware/gzip/gzip.go
@@ -64,6 +64,15 @@ type gzipResponseWriter struct {
http.ResponseWriter
}
+// WriteHeader wraps the underlying WriteHeader method to prevent
+// problems with conflicting headers from proxied backends. For
+// example, a backend system that calculates Content-Length would
+// be wrong because it doesn't know it's being gzipped.
+func (w gzipResponseWriter) WriteHeader(code int) {
+ w.Header().Del("Content-Length")
+ w.ResponseWriter.WriteHeader(code)
+}
+
// Write wraps the underlying Write method to do compression.
func (w gzipResponseWriter) Write(b []byte) (int, error) {
if w.Header().Get("Content-Type") == "" {