close closable body after request

This commit is contained in:
Ringo Hoffmann 2022-01-28 17:06:32 +01:00
parent b51247bb2c
commit 341db84788
No known key found for this signature in database
GPG Key ID: 5DE1487DA08E34FE

View File

@ -14,10 +14,10 @@ func (c *Client) req(method, path string, body io.Reader, intercept func(*http.R
var retryBuf io.Reader
if body != nil {
// Because Request#Do closes closable streams, Seeker#Seek
// will fail on retry because stream is already closed.
// This inhibits the closing of the passed stream.
if cl, ok := body.(io.Closer); ok {
body = closeInhibitor{body}
defer cl.Close()
}
// If the authorization fails, we will need to restart reading
// from the passed body stream.
// When body is seekable, use seek to reset the streams
@ -28,7 +28,6 @@ func (c *Client) req(method, path string, body io.Reader, intercept func(*http.R
if _, err = sk.Seek(0, io.SeekStart); err != nil {
return
}
retryBuf = body
} else {
buff := &bytes.Buffer{}
retryBuf = buff