mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-24 08:12:38 +02:00
Allow compression at the transport level. (#595)
* Allow compression at the transport level. * Do not enable compression but do decompress compressed content-encodings. * Fix import in download.go to use std compress/go. * Fix issue with err shadowing. * Don't overwrite resBody on download of original image. Set content length to 0 if data was compressed.
This commit is contained in:
parent
83c4ef1ea8
commit
c7fcb9b94f
18
download.go
18
download.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
@ -200,7 +201,22 @@ func downloadImage(ctx context.Context) (context.Context, context.CancelFunc, er
|
||||
return ctx, func() {}, err
|
||||
}
|
||||
|
||||
imgdata, err := readAndCheckImage(res.Body, int(res.ContentLength))
|
||||
body := res.Body
|
||||
contentLength := int(res.ContentLength)
|
||||
|
||||
if res.Header.Get("Content-Encoding") == "gzip" {
|
||||
gzipBody, errGzip := gzip.NewReader(res.Body)
|
||||
if gzipBody != nil {
|
||||
defer gzipBody.Close()
|
||||
}
|
||||
if errGzip != nil {
|
||||
return ctx, func() {}, err
|
||||
}
|
||||
body = gzipBody
|
||||
contentLength = 0
|
||||
}
|
||||
|
||||
imgdata, err := readAndCheckImage(body, contentLength)
|
||||
if err != nil {
|
||||
return ctx, func() {}, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user