nytimes / gziphandler

Go middleware to gzip HTTP responses
https://godoc.org/github.com/NYTimes/gziphandler
Apache License 2.0
868 stars 129 forks source link

Start plain response as soon as certain #74

Closed victorges closed 6 years ago

victorges commented 6 years ago

Using this library in one of my projects, I came to realise our API for Server-Sent Events stopped working when the request included an Accept-Encoding: gzip header.

Investigating on the gziphandler code I found out that, even though I added only application/json as the list of supported content types to be GZIPped, 2 little issues led to SSE stop working:

One thing that is still slightly bothering me is that we are parsing the response headers every time the Write function is called. I'm thinking of adding a little "state-enum" in the gzip.Writer struct, indicating whether:

I think this will make the logic much clearer as well. Please also let me know what you think of that idea and I could try to send it as a separate pull-request!

victorges commented 6 years ago

Great! I think I don't have access to merging this though, could you do it for me?

I'll try to do the state thing some time in the next few days :)

jprobinson commented 6 years ago

Thanks, @victorges & @fsouza!