mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-26 19:46:43 +02:00
Properly close gzipped response body
This commit is contained in:
@@ -178,7 +178,10 @@ func wrapGzipBody(res *http.Response) error {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
res.Body = gzipBody
|
||||
res.Body = &gzipReadCloser{
|
||||
Reader: gzipBody,
|
||||
r: res.Body,
|
||||
}
|
||||
res.Header.Del(httpheaders.ContentEncoding)
|
||||
}
|
||||
|
||||
@@ -202,3 +205,15 @@ func (r *bodyReader) Close() error {
|
||||
defer r.request.cancel()
|
||||
return r.body.Close()
|
||||
}
|
||||
|
||||
// gzipReadCloser is a wrapper around gzip.Reader which also closes the original body
|
||||
type gzipReadCloser struct {
|
||||
*gzip.Reader
|
||||
r io.ReadCloser
|
||||
}
|
||||
|
||||
// Close closes the gzip reader and the original body
|
||||
func (gr *gzipReadCloser) Close() error {
|
||||
gr.Reader.Close()
|
||||
return gr.r.Close()
|
||||
}
|
||||
|
Reference in New Issue
Block a user