mirror of
https://git.phreedom.club/localhost_frssoft/compy.git
synced 2024-11-05 16:03:19 +00:00
Merge branch 'feat/gzip-compression-level'
* feat/gzip-compression-level: Allow configuration of gzip compression level
This commit is contained in:
commit
7b3424fd18
5
compy.go
5
compy.go
|
@ -20,6 +20,7 @@ var (
|
|||
|
||||
jpeg = flag.Int("jpeg", 50, "jpeg quality (1-100, 0 to disable)")
|
||||
gif = flag.Bool("gif", true, "transcode gifs into static images")
|
||||
gzip = flag.Int("gzip", -1, "gzip compression level (0-9, default 6)")
|
||||
png = flag.Bool("png", true, "transcode png")
|
||||
minify = flag.Bool("minify", false, "minify css/html/js - WARNING: tends to break the web")
|
||||
)
|
||||
|
@ -55,9 +56,9 @@ func main() {
|
|||
|
||||
var ttc proxy.Transcoder
|
||||
if *minify {
|
||||
ttc = &tc.Gzip{tc.NewMinifier(), false}
|
||||
ttc = &tc.Gzip{tc.NewMinifier(), *gzip, false}
|
||||
} else {
|
||||
ttc = &tc.Gzip{&tc.Identity{}, true}
|
||||
ttc = &tc.Gzip{&tc.Identity{}, *gzip, true}
|
||||
}
|
||||
|
||||
p.AddTranscoder("text/css", ttc)
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue