Skip to content

Commit

Permalink
Support gzip compression
Browse files Browse the repository at this point in the history
  • Loading branch information
Jipok committed Jul 13, 2024
1 parent ee93cdf commit 01d33da
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
)

require (
github.com/klauspost/compress v1.17.9 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/suyashkumar/ssl-proxy v0.2.7 h1:X5k4illkdJ8KUqW7J0FIYq+/BN3vgO8w12VXN/bBKG8=
github.com/suyashkumar/ssl-proxy v0.2.7/go.mod h1:9RJabvB5YHnz8lIulJp4Xe+BD7RYqEnRvUx6W8BVnuQ=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Config struct {
Key string
}
FilterSpam bool
Gzip bool
DropPrivileges bool
Listen string
HttpsPort string
Expand Down Expand Up @@ -113,6 +114,7 @@ func main() {
cfg.Certificate.Type = "self-signed"
cfg.DefaultTarget = "8080"
cfg.FilterSpam = true // Less spam like `http: TLS handshake error...`
cfg.Gzip = true // Enable gzip'ing the responses
cfg.DropPrivileges = false // Drop privileges if started from root
cfg.Listen = "0.0.0.0" // Interface to listen
cfg.HttpsPort = "443"
Expand Down
19 changes: 18 additions & 1 deletion ssl-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

"github.com/klauspost/compress/gzhttp"
"github.com/suyashkumar/ssl-proxy/gen"
"golang.org/x/crypto/acme/autocert"
)
Expand Down Expand Up @@ -109,14 +110,22 @@ func startWebServer() {
} else {
domains = append(domains, d.Domain)
}
// TODO Подсвечивать дубликаты портов
log.Printf(green("Proxying from https://%s to %s"), d.Domain, toURL)
}
if cfg.Certificate.Type == "autocert" {
log.Print("With autocert using HostWhitelist: ", strings.Join(domains, ", "))
}

// TODO Is possible add http/2 support?
// transport := &http.Transport{
// ForceAttemptHTTP2: true,
// }
// http2.ConfigureTransport(transport)

// Setup reverse proxy
proxy := &httputil.ReverseProxy{
var proxy http.Handler = &httputil.ReverseProxy{
// Transport: transport,
Rewrite: func(r *httputil.ProxyRequest) {
// Use default target(with empty domain) for everything we don't know how to redirect
target := toURLs[r.In.Host]
Expand All @@ -134,6 +143,14 @@ func startWebServer() {
w.Write(embed_502_html)
},
}

if cfg.Gzip {
wrapper, err := gzhttp.NewWrapper(gzhttp.KeepAcceptRanges())
if err != nil {
log.Fatalf("Unable to create gzip wrapper: %s", err)
}
proxy = wrapper(proxy)
}
// See auth-handler.go
mux := newAuthMux(proxy)

Expand Down

0 comments on commit 01d33da

Please sign in to comment.