mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-30 14:06:48 +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 {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
res.Body = gzipBody
|
res.Body = &gzipReadCloser{
|
||||||
|
Reader: gzipBody,
|
||||||
|
r: res.Body,
|
||||||
|
}
|
||||||
res.Header.Del(httpheaders.ContentEncoding)
|
res.Header.Del(httpheaders.ContentEncoding)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,3 +205,15 @@ func (r *bodyReader) Close() error {
|
|||||||
defer r.request.cancel()
|
defer r.request.cancel()
|
||||||
return r.body.Close()
|
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