mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-03-17 20:17:48 +02:00
Limit idle conections; Close response body on error
This commit is contained in:
parent
e566aedcc3
commit
4a89f0c355
11
download.go
11
download.go
@ -8,6 +8,7 @@ import (
|
||||
"image"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
@ -56,7 +57,11 @@ func (lr *limitReader) Close() error {
|
||||
|
||||
func initDownloading() {
|
||||
transport := &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
MaxIdleConns: conf.Concurrency,
|
||||
MaxIdleConnsPerHost: conf.Concurrency,
|
||||
DisableCompression: true,
|
||||
Dial: (&net.Dialer{KeepAlive: 600 * time.Second}).Dial,
|
||||
}
|
||||
|
||||
if conf.IgnoreSslVerification {
|
||||
@ -176,10 +181,12 @@ func downloadImage(ctx context.Context) (context.Context, context.CancelFunc, er
|
||||
req.Header.Set("User-Agent", conf.UserAgent)
|
||||
|
||||
res, err := downloadClient.Do(req)
|
||||
if res != nil {
|
||||
defer res.Body.Close()
|
||||
}
|
||||
if err != nil {
|
||||
return ctx, func() {}, newError(404, err.Error(), msgSourceImageIsUnreachable)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != 200 {
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
Loading…
x
Reference in New Issue
Block a user