-
Notifications
You must be signed in to change notification settings - Fork 271
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
compress: introduce CompressHandlerLevel #48
Conversation
@@ -48,7 +57,7 @@ func CompressHandler(h http.Handler) http.Handler { | |||
w.Header().Set("Content-Encoding", "gzip") | |||
w.Header().Add("Vary", "Accept-Encoding") | |||
|
|||
gw := gzip.NewWriter(w) | |||
gw, _ := gzip.NewWriterLevel(w, level) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of ignoring the error, we should check the level
is within acceptable bounds, else we will run into undefined behaviour. If not, we should just set gzip.DefaultCompression
as the level. Cover this in the function docs.
Thanks @flyingmutant! Are you able to address my comment and add a test to check that a |
Thanks for the review! Does it look OK now? |
@elithrar, any updates here? |
[feature] CompressHandler: introduce CompressHandlerLevel
Whoops, sorry @flyingmutant - missed this! Looks good to me: thanks for contributing 👍 |
One thing I wanted to add (for posterity): make sure to benchmark the CPU impact on the client (i.e. a mobile device!) when increasing compression. Slightly better compression over the wire may not be ideal in those cases. Using something like |
CompressHandlerLevel
allows to specify a compression level explicitly. This allows clients to use e.g.gzip.BestCompression
, which often results in major bandwidth savings.