MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / wrapGzipBody

Function wrapGzipBody

fetcher/request.go:163–177  ·  view source on GitHub ↗

wrapGzipBody wraps the response body in a gzip reader if the Content-Encoding is gzip. We set DisableCompression: true to avoid sending the Accept-Encoding: gzip header, since we do not want to compress image data (which is usually already compressed). However, some servers still send gzip-encoded r

(res *http.Response)

Source from the content-addressed store, hash-verified

161// since we do not want to compress image data (which is usually already compressed).
162// However, some servers still send gzip-encoded responses regardless.
163func wrapGzipBody(res *http.Response) error {
164 if res.Header.Get(httpheaders.ContentEncoding) == "gzip" {
165 gzipBody, err := gzip.NewReader(res.Body)
166 if err != nil {
167 return err
168 }
169 res.Body = &gzipReadCloser{
170 Reader: gzipBody,
171 r: res.Body,
172 }
173 res.Header.Del(httpheaders.ContentEncoding)
174 }
175
176 return nil
177}
178
179// gzipReadCloser is a wrapper around gzip.Reader which also closes the original body
180type gzipReadCloser struct {

Callers 1

FetchMethod · 0.85

Calls 1

GetMethod · 0.65

Tested by

no test coverage detected