]> Sergey Matveev's repositories - godlighty.git/commitdiff
-no-gzip
authorSergey Matveev <stargrave@stargrave.org>
Mon, 2 Mar 2026 14:45:03 +0000 (17:45 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 2 Mar 2026 14:45:12 +0000 (17:45 +0300)
cmd/godlighty/main.go
handler.go

index c65979ba24e7c8970e29b0c6beda6448abd2c4ac..40f9e37731b1ba076d1792b86931bf847a12046f 100644 (file)
@@ -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,
index 43fa36ae0bdb2b9e00bca4d2ca64ecccf500d0d8..e31a034bd5ea7cfea62d9822c0427899d5c37d4c 100644 (file)
@@ -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)