From 9f55dea1620b3a61c811c00d9616d144f737b4b0 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 5 Jun 2020 21:37:10 +0300 Subject: [PATCH] lib/httpserver: do not flush and do not close gzip writer if response compression is disabled Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/535 --- lib/httpserver/httpserver.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/httpserver/httpserver.go b/lib/httpserver/httpserver.go index 3ee057d28..c4930c809 100644 --- a/lib/httpserver/httpserver.go +++ b/lib/httpserver/httpserver.go @@ -336,11 +336,13 @@ func (zrw *gzipResponseWriter) writeHeader() { // Implements http.Flusher func (zrw *gzipResponseWriter) Flush() { - if err := zrw.bw.Flush(); err != nil && !isTrivialNetworkError(err) { - logger.Warnf("gzipResponseWriter.Flush (buffer): %s", err) - } - if err := zrw.zw.Flush(); err != nil && !isTrivialNetworkError(err) { - logger.Warnf("gzipResponseWriter.Flush (gzip): %s", err) + if !zrw.disableCompression { + if err := zrw.bw.Flush(); err != nil && !isTrivialNetworkError(err) { + logger.Warnf("gzipResponseWriter.Flush (buffer): %s", err) + } + if err := zrw.zw.Flush(); err != nil && !isTrivialNetworkError(err) { + logger.Warnf("gzipResponseWriter.Flush (gzip): %s", err) + } } if fw, ok := zrw.ResponseWriter.(http.Flusher); ok { fw.Flush() @@ -353,7 +355,10 @@ func (zrw *gzipResponseWriter) Close() error { return nil } zrw.Flush() - err := zrw.zw.Close() + var err error + if !zrw.disableCompression { + err = zrw.zw.Close() + } putGzipWriter(zrw.zw) zrw.zw = nil putBufioWriter(zrw.bw)