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

Use deferred Gzip closing #8

Closed xthezealot closed 8 years ago

xthezealot commented 8 years ago

When there is something to close, use deferred functions. Otherwise, in this case, the Gzip writer will never be closed nor put back in the pool if a downstream handler panics.

Of course, we still close the writer before putting it back in the pool as deferred function calls are LIFO executed.

Also, DEFAULT_QVALUE should be changed to DefaultQvalue and e := make([]string, 0) to var e []string.

bmizerany commented 8 years ago

+1. I noticed this too and almost sent a patch.

adammck commented 8 years ago

Good catch, thanks. No idea why I didn't use defer here in the first place.