Allow configuration of gzip compression level

This commit is contained in:
Andrew Gaul
2017-01-15 10:30:41 -08:00
committed by Barna Csorogi
parent b23411caf2
commit ca005f7c97
2 changed files with 9 additions and 4 deletions

View File

@ -9,7 +9,8 @@ import (
type Gzip struct {
proxy.Transcoder
SkipGzipped bool
CompressionLevel int
SkipGzipped bool
}
func (t *Gzip) Transcode(w *proxy.ResponseWriter, r *proxy.ResponseReader, headers http.Header) error {
@ -33,7 +34,10 @@ func (t *Gzip) Transcode(w *proxy.ResponseWriter, r *proxy.ResponseReader, heade
}
if shouldGzip && compress(r) {
gzw := gzip.NewWriter(w.Writer)
gzw, err := gzip.NewWriterLevel(w.Writer, t.CompressionLevel)
if err != nil {
return err
}
defer gzw.Flush()
w.Writer = gzw
w.Header().Set("Content-Encoding", "gzip")