mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-24 08:12:38 +02:00
Retry source image request if http connection was lost
This commit is contained in:
parent
2c28252966
commit
168f6f6043
@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
@ -164,12 +165,27 @@ func BuildImageRequest(ctx context.Context, imageURL string, header http.Header,
|
||||
}
|
||||
|
||||
func SendRequest(req *http.Request) (*http.Response, error) {
|
||||
res, err := downloadClient.Do(req)
|
||||
if err != nil {
|
||||
for {
|
||||
res, err := downloadClient.Do(req)
|
||||
if err == nil {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
if res != nil && res.Body != nil {
|
||||
res.Body.Close()
|
||||
}
|
||||
|
||||
if strings.Contains(err.Error(), "client connection lost") {
|
||||
select {
|
||||
case <-req.Context().Done():
|
||||
return nil, err
|
||||
case <-time.After(100 * time.Microsecond):
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return nil, wrapError(err)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func requestImage(ctx context.Context, imageURL string, opts DownloadOptions) (*http.Response, context.CancelFunc, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user