Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpgzip.NewHandler breaks when used with httputil.NewSingleHostReverseProxy #6

Open
nwidger opened this issue Dec 9, 2014 · 0 comments

Comments

@nwidger
Copy link

nwidger commented Dec 9, 2014

When httputil.NewSingleHostReverseProxy is wrapped with httpgzip.NewHandler, i.e.

http.Handle("/", httpgzip.NewHandler(httputil.NewSingleHostReverseProxy(target)))

the call to w.Writer.Write in gzipResponseWriter.Write returns 0, ErrContentLength ("Conn.Write wrote more than the declared Content-Length"). I believe this is because ReverseProxy.ServeHTTP calls ResponseWriter.WriteHeader which stores the current (pre-gzip) Content-Length value in the response before it writes the body out.

I was able to fix this problem by adding this method to gzipResponseWriter:

func (w *gzipResponseWriter) WriteHeader(code int) {
    w.Header().Del("Content-Length")
    w.ResponseWriter.WriteHeader(code)
}
@nwidger nwidger changed the title httpgzip.NewHandler breaks when used with httputil.NewSingleHostReverseProxy httpgzip.NewHandler breaks when used with httputil.NewSingleHostReverseProxy Dec 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant