lib/httpserver: prefer gzip over zstd compression for http responses if the client indicates it supports both methods

This is needed because some clients and proxies improperly handle zstd-compressed responses.
See https://github.com/VictoriaMetrics/victoriametrics-datasource/issues/455 .

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/10535
This commit is contained in:
Aliaksandr Valialkin
2026-02-25 21:49:41 +01:00
parent 216821aa1c
commit cd2026e430
2 changed files with 9 additions and 1 deletions

View File

@@ -273,7 +273,14 @@ func stop(addr string) error {
}
var gzipHandlerWrapper = func() func(http.Handler) http.HandlerFunc {
hw, err := gzhttp.NewWrapper(gzhttp.CompressionLevel(1))
hw, err := gzhttp.NewWrapper(
gzhttp.CompressionLevel(1),
// Prefer gzip over zstd compression if the client supports both methods
// because some intermediate proxies improperly handle zstd-compressed responses.
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/10535
gzhttp.PreferZstd(false),
)
if err != nil {
panic(fmt.Errorf("BUG: cannot initialize gzip http wrapper: %w", err))
}