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)
| 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. |
| 163 | func 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 |
| 180 | type gzipReadCloser struct { |