Do not close the body too early
This commit is contained in:
@@ -181,6 +181,9 @@ func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) {
|
|||||||
attempt := 0
|
attempt := 0
|
||||||
for {
|
for {
|
||||||
resp, err = r.client.Do(req)
|
resp, err = r.client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
defer resp.Body.Close()
|
||||||
|
}
|
||||||
if resp != nil && (resp.StatusCode < http.StatusOK || resp.StatusCode > http.StatusPartialContent) {
|
if resp != nil && (resp.StatusCode < http.StatusOK || resp.StatusCode > http.StatusPartialContent) {
|
||||||
body, _ := io.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
if body != nil {
|
if body != nil {
|
||||||
@@ -193,9 +196,6 @@ func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
incr := r.getRetryIncr(resp, reqHasRangeHeader, err)
|
incr := r.getRetryIncr(resp, reqHasRangeHeader, err)
|
||||||
if resp != nil {
|
|
||||||
resp.Body.Close()
|
|
||||||
}
|
|
||||||
if incr > 0 {
|
if incr > 0 {
|
||||||
attempt += incr
|
attempt += incr
|
||||||
if attempt > r.maxRetries {
|
if attempt > r.maxRetries {
|
||||||
|
|||||||
Reference in New Issue
Block a user