mirror of
https://git.phreedom.club/localhost_frssoft/compy.git
synced 2024-11-23 16:41:30 +00:00
Some mini changes
This commit is contained in:
parent
fe1404de80
commit
264931d574
|
@ -1,6 +1,9 @@
|
||||||
Compy
|
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.
|
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.
|
One use case is to reduce bandwidth usage when browsing on limited mobile broadband connection.
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ func (t *Gif) Transcode(w *proxy.ResponseWriter, r *proxy.ResponseReader, header
|
||||||
if SupportsWebP(headers) {
|
if SupportsWebP(headers) {
|
||||||
w.Header().Set("Content-Type", "image/webp")
|
w.Header().Set("Content-Type", "image/webp")
|
||||||
options := webp.Options{
|
options := webp.Options{
|
||||||
Lossless: true,
|
Lossless: false,
|
||||||
}
|
}
|
||||||
if err = webp.Encode(w, img, &options); err != nil {
|
if err = webp.Encode(w, img, &options); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"github.com/chai2010/webp"
|
"github.com/chai2010/webp"
|
||||||
"github.com/pixiv/go-libjpeg/jpeg"
|
"github.com/pixiv/go-libjpeg/jpeg"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Jpeg struct {
|
type Jpeg struct {
|
||||||
|
@ -30,20 +29,13 @@ func (t *Jpeg) Transcode(w *proxy.ResponseWriter, r *proxy.ResponseReader, heade
|
||||||
}
|
}
|
||||||
|
|
||||||
encOptions := t.encOptions
|
encOptions := t.encOptions
|
||||||
qualityString := headers.Get("X-Compy-Quality")
|
encOptions.Quality = 70
|
||||||
if qualityString != "" {
|
|
||||||
if quality, err := strconv.Atoi(qualityString); err != nil {
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
encOptions.Quality = quality
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if SupportsWebP(headers) {
|
if SupportsWebP(headers) {
|
||||||
w.Header().Set("Content-Type", "image/webp")
|
w.Header().Set("Content-Type", "image/webp")
|
||||||
options := webp.Options{
|
options := webp.Options{
|
||||||
Lossless: false,
|
Lossless: false,
|
||||||
Quality: float32(encOptions.Quality),
|
Quality: float32(encOptions.Quality - 20),
|
||||||
}
|
}
|
||||||
if err = webp.Encode(w, img, &options); err != nil {
|
if err = webp.Encode(w, img, &options); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -18,7 +18,7 @@ func (t *Png) Transcode(w *proxy.ResponseWriter, r *proxy.ResponseReader, header
|
||||||
if SupportsWebP(headers) {
|
if SupportsWebP(headers) {
|
||||||
w.Header().Set("Content-Type", "image/webp")
|
w.Header().Set("Content-Type", "image/webp")
|
||||||
options := webp.Options{
|
options := webp.Options{
|
||||||
Lossless: true,
|
Lossless: false,
|
||||||
}
|
}
|
||||||
if err = webp.Encode(w, img, &options); err != nil {
|
if err = webp.Encode(w, img, &options); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -51,13 +51,13 @@ func (t *Zip) Transcode(w *proxy.ResponseWriter, r *proxy.ResponseReader, header
|
||||||
|
|
||||||
if shouldBrotli && compress(r) {
|
if shouldBrotli && compress(r) {
|
||||||
params := brotlienc.NewBrotliParams()
|
params := brotlienc.NewBrotliParams()
|
||||||
params.SetQuality(t.BrotliCompressionLevel)
|
params.SetQuality(11)
|
||||||
brw := brotlienc.NewBrotliWriter(params, w.Writer)
|
brw := brotlienc.NewBrotliWriter(params, w.Writer)
|
||||||
defer brw.Close()
|
defer brw.Close()
|
||||||
w.Writer = brw
|
w.Writer = brw
|
||||||
w.Header().Set("Content-Encoding", "br")
|
w.Header().Set("Content-Encoding", "br")
|
||||||
} else if shouldGzip && compress(r) {
|
} else if shouldGzip && compress(r) {
|
||||||
gzw, err := gzip.NewWriterLevel(w.Writer, t.GzipCompressionLevel)
|
gzw, err := gzip.NewWriterLevel(w.Writer, 9)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -69,5 +69,5 @@ func (t *Zip) Transcode(w *proxy.ResponseWriter, r *proxy.ResponseReader, header
|
||||||
}
|
}
|
||||||
|
|
||||||
func compress(r *proxy.ResponseReader) bool {
|
func compress(r *proxy.ResponseReader) bool {
|
||||||
return r.Header().Get("Content-Encoding") == ""
|
return true // Always compression
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue