From 264931d5744309e6fc2c0b7f8d31ed39fbae0617 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Sat, 7 Jan 2023 01:38:45 +0300 Subject: [PATCH] Some mini changes --- README.md | 3 +++ transcoder/gif.go | 2 +- transcoder/jpeg.go | 12 ++---------- transcoder/png.go | 2 +- transcoder/zip.go | 6 +++--- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 0d56e21..6fabbcc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ Compy ===== +Forked from upstream: https://github.com/barnacs/compy +Main changes in this fork/branch is maximum of compression by default (worst quality) + Compy is an HTTP/HTTPS forward proxy with content compression/transcoding capabilities. One use case is to reduce bandwidth usage when browsing on limited mobile broadband connection. diff --git a/transcoder/gif.go b/transcoder/gif.go index a4901b6..0f32b73 100644 --- a/transcoder/gif.go +++ b/transcoder/gif.go @@ -17,7 +17,7 @@ func (t *Gif) Transcode(w *proxy.ResponseWriter, r *proxy.ResponseReader, header if SupportsWebP(headers) { w.Header().Set("Content-Type", "image/webp") options := webp.Options{ - Lossless: true, + Lossless: false, } if err = webp.Encode(w, img, &options); err != nil { return err diff --git a/transcoder/jpeg.go b/transcoder/jpeg.go index c6368cf..2a120b0 100644 --- a/transcoder/jpeg.go +++ b/transcoder/jpeg.go @@ -5,7 +5,6 @@ import ( "github.com/chai2010/webp" "github.com/pixiv/go-libjpeg/jpeg" "net/http" - "strconv" ) type Jpeg struct { @@ -30,20 +29,13 @@ func (t *Jpeg) Transcode(w *proxy.ResponseWriter, r *proxy.ResponseReader, heade } encOptions := t.encOptions - qualityString := headers.Get("X-Compy-Quality") - if qualityString != "" { - if quality, err := strconv.Atoi(qualityString); err != nil { - return err - } else { - encOptions.Quality = quality - } - } + encOptions.Quality = 70 if SupportsWebP(headers) { w.Header().Set("Content-Type", "image/webp") options := webp.Options{ Lossless: false, - Quality: float32(encOptions.Quality), + Quality: float32(encOptions.Quality - 20), } if err = webp.Encode(w, img, &options); err != nil { return err diff --git a/transcoder/png.go b/transcoder/png.go index 06a6fea..d7adcf1 100644 --- a/transcoder/png.go +++ b/transcoder/png.go @@ -18,7 +18,7 @@ func (t *Png) Transcode(w *proxy.ResponseWriter, r *proxy.ResponseReader, header if SupportsWebP(headers) { w.Header().Set("Content-Type", "image/webp") options := webp.Options{ - Lossless: true, + Lossless: false, } if err = webp.Encode(w, img, &options); err != nil { return err diff --git a/transcoder/zip.go b/transcoder/zip.go index 629bbcc..65d92c0 100644 --- a/transcoder/zip.go +++ b/transcoder/zip.go @@ -51,13 +51,13 @@ func (t *Zip) Transcode(w *proxy.ResponseWriter, r *proxy.ResponseReader, header if shouldBrotli && compress(r) { params := brotlienc.NewBrotliParams() - params.SetQuality(t.BrotliCompressionLevel) + params.SetQuality(11) brw := brotlienc.NewBrotliWriter(params, w.Writer) defer brw.Close() w.Writer = brw w.Header().Set("Content-Encoding", "br") } else if shouldGzip && compress(r) { - gzw, err := gzip.NewWriterLevel(w.Writer, t.GzipCompressionLevel) + gzw, err := gzip.NewWriterLevel(w.Writer, 9) if err != nil { return err } @@ -69,5 +69,5 @@ func (t *Zip) Transcode(w *proxy.ResponseWriter, r *proxy.ResponseReader, header } func compress(r *proxy.ResponseReader) bool { - return r.Header().Get("Content-Encoding") == "" + return true // Always compression }