diff --git a/go.mod b/go.mod index ba1b307..1bc0750 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 7c80d11..653943e 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/main.go b/main.go index c41cd55..83298e5 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,7 @@ type Config struct { Key string } FilterSpam bool + Gzip bool DropPrivileges bool Listen string HttpsPort string @@ -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" diff --git a/ssl-proxy.go b/ssl-proxy.go index 12cc5ce..8f95fad 100644 --- a/ssl-proxy.go +++ b/ssl-proxy.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "github.com/klauspost/compress/gzhttp" "github.com/suyashkumar/ssl-proxy/gen" "golang.org/x/crypto/acme/autocert" ) @@ -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] @@ -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)