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

Set detected Content-Type only when not already set #96

Open rtribotte opened 4 years ago

rtribotte commented 4 years ago

This PR introduce a condition to set the Content-Type header, backed by a new test.

The goal is to have the identical behavior as the http/server and http/fs does.

Content-Type header will only be set with the detected MIME type if it is not already set, which means no header previously set (at all). So the condition to set the header is when there is no existing key for the Content-Type header in the response writer map.

The purpose of handling the nil value could be seen as the capacity to disable content type detection, and at the same time, not having the Content-Type header in the resulting response for the client.