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
@ -8,6 +8,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@ -57,6 +58,10 @@ func (lr *limitReader) Close() error {
|
|||||||
func initDownloading() {
|
func initDownloading() {
|
||||||
transport := &http.Transport{
|
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 {
|
if conf.IgnoreSslVerification {
|
||||||
@ -176,10 +181,12 @@ func downloadImage(ctx context.Context) (context.Context, context.CancelFunc, er
|
|||||||
req.Header.Set("User-Agent", conf.UserAgent)
|
req.Header.Set("User-Agent", conf.UserAgent)
|
||||||
|
|
||||||
res, err := downloadClient.Do(req)
|
res, err := downloadClient.Do(req)
|
||||||
|
if res != nil {
|
||||||
|
defer res.Body.Close()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx, func() {}, newError(404, err.Error(), msgSourceImageIsUnreachable)
|
return ctx, func() {}, newError(404, err.Error(), msgSourceImageIsUnreachable)
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
|
||||||
|
|
||||||
if res.StatusCode != 200 {
|
if res.StatusCode != 200 {
|
||||||
body, _ := ioutil.ReadAll(res.Body)
|
body, _ := ioutil.ReadAll(res.Body)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user