From c8d6e88b6fc818d94f56d38be0a77517527cd3fa Mon Sep 17 00:00:00 2001 From: koenno <8572607+koenno@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:42:30 +0200 Subject: [PATCH] discard gzip footer when empty body --- handler.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/handler.go b/handler.go index fccfa93..ee9eb9f 100644 --- a/handler.go +++ b/handler.go @@ -54,6 +54,10 @@ func (g *gzipHandler) Handle(c *gin.Context) { c.Header("Vary", "Accept-Encoding") c.Writer = &gzipWriter{c.Writer, gz} defer func() { + if c.Writer.Size() < 0 { + // do not write gzip footer when nothing is written to the response body + gz.Reset(io.Discard) + } gz.Close() c.Header("Content-Length", fmt.Sprint(c.Writer.Size())) }()