Some mini changes

This commit is contained in:
localhost_frssoft 2023-01-07 01:38:45 +03:00
parent fe1404de80
commit 264931d574
5 changed files with 10 additions and 15 deletions

View file

@ -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.

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
}