daaku / go.httpgzip

Package httpgzip provides a http handler wrapper to transparently add gzip compression.
https://godoc.org/github.com/daaku/go.httpgzip
62 stars 6 forks source link

Remove Content-Length header #7

Closed mstetson closed 6 years ago

mstetson commented 8 years ago

If a wrapped handler adds a Content-Length header to the response (as does http.FileServer), it will not match the gzipped length, confusing the client. This change ensures any Content-Length header is removed, even if the client calls WriteHeader explicitly.

rlk833 commented 6 years ago

@daaku We just ran into this issue too. We spent two full days trying to figure out why things were failing. Please accept this pull request. It is far too easy for someone else to run into this too.

mstetson commented 6 years ago

Though I believe my pull request does fix this specific issue, I ran into several other problems using my fork in production over the year following the pull request. In the end, I wrote something more complex, but I believe more robust. I've been using it in our code for about 15 months now. You may want to take a look: https://bitbucket.org/classroomsystems/gziphandler/

daaku commented 6 years ago

There's also https://github.com/NYTimes/gziphandler. I just added a note to the readme saying don't use this library.