Skip to content

Commit

Permalink
chore: discard gzip footer when empty body (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
koenno authored Dec 24, 2024
1 parent a1786dc commit fb15f54
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}()
Expand Down

0 comments on commit fb15f54

Please sign in to comment.