From: Sergey Matveev Date: Mon, 2 Mar 2026 14:45:03 +0000 (+0300) Subject: -no-gzip X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=2acf63a57149d0fc85edf10e164c2f59dfed8d2c;p=godlighty.git -no-gzip --- diff --git a/cmd/godlighty/main.go b/cmd/godlighty/main.go index c65979b..40f9e37 100644 --- a/cmd/godlighty/main.go +++ b/cmd/godlighty/main.go @@ -47,6 +47,7 @@ func main() { bind := flag.String("bind", "[::]:80", "Address to bind and listen on") doTLS := flag.Bool("tls", false, "Enable TLS") noH2 := flag.Bool("no-h2", false, "Disable HTTP/2") + noGzip := flag.Bool("no-gzip", false, "Disable gzip compression support") doSetUID := flag.Int("setuid", 0, "Set that UID after binding the socket") doSetGID := flag.Int("setgid", 0, "Set that GID after binding the socket") doSetGIDs := flag.String("setgids", "", "Comma-separated GIDs to set") @@ -104,6 +105,9 @@ func main() { } }() + if *noGzip { + godlighty.NoGzip = true + } godlighty.BindAddr = *bind srv := http.Server{ Handler: godlighty.MainHandler, diff --git a/handler.go b/handler.go index 43fa36a..e31a034 100644 --- a/handler.go +++ b/handler.go @@ -45,6 +45,8 @@ const ( ) var ( + NoGzip bool + gzPool = sync.Pool{ New: func() any { return gzip.NewWriter(io.Discard) }, } @@ -308,7 +310,7 @@ SkipMeta4: zstdW.Reset(bufCompressed) defer zstdW.Close() wc = &gzipResponseWriter{ResponseWriter: w, Writer: zstdW} - } else if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { + } else if !NoGzip && strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { w.Header().Set("Content-Encoding", "gzip") gz = gzPool.Get().(*gzip.Writer) defer gzPool.Put(gz)