Skip to content

Commit

Permalink
refactor: optimize gzip writer pool management and resource handling (#…
Browse files Browse the repository at this point in the history
…102)

- Remove deferred function that resets and puts the gzip writer back into the pool
- Add immediate return of the gzip writer to the pool after resetting it

Signed-off-by: appleboy <[email protected]>
  • Loading branch information
appleboy authored Jan 27, 2025
1 parent 4fc267c commit aa5d8ee
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ func (g *gzipHandler) Handle(c *gin.Context) {
}

gz := g.gzPool.Get().(*gzip.Writer)
defer func() {
gz.Reset(io.Discard)
g.gzPool.Put(gz)
}()
gz.Reset(c.Writer)

c.Header(headerContentEncoding, "gzip")
Expand All @@ -98,6 +94,7 @@ func (g *gzipHandler) Handle(c *gin.Context) {
if c.Writer.Size() > -1 {
c.Header("Content-Length", strconv.Itoa(c.Writer.Size()))
}
g.gzPool.Put(gz)
}()
c.Next()
}
Expand Down

0 comments on commit aa5d8ee

Please sign in to comment.