Fix retries on req body reads
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -144,8 +145,15 @@ func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) {
|
||||
var resp *http.Response
|
||||
var err error
|
||||
attempt := 0
|
||||
var origBody []byte
|
||||
if req.Method == "POST" {
|
||||
origBody, _ = io.ReadAll(req.Body)
|
||||
}
|
||||
|
||||
for {
|
||||
if origBody != nil {
|
||||
req.Body = io.NopCloser(bytes.NewReader(origBody))
|
||||
}
|
||||
if resp != nil && resp.Body != nil {
|
||||
resp.Body.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user