Allow configuration of gzip compression level
This commit is contained in:
committed by
Barna Csorogi
parent
b23411caf2
commit
ca005f7c97
@ -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")
|
||||
|
Reference in New Issue
Block a user