close closable body after request
This commit is contained in:
parent
b51247bb2c
commit
341db84788
@ -14,10 +14,10 @@ func (c *Client) req(method, path string, body io.Reader, intercept func(*http.R
|
|||||||
var retryBuf io.Reader
|
var retryBuf io.Reader
|
||||||
|
|
||||||
if body != nil {
|
if body != nil {
|
||||||
// Because Request#Do closes closable streams, Seeker#Seek
|
if cl, ok := body.(io.Closer); ok {
|
||||||
// will fail on retry because stream is already closed.
|
body = closeInhibitor{body}
|
||||||
// This inhibits the closing of the passed stream.
|
defer cl.Close()
|
||||||
body = closeInhibitor{body}
|
}
|
||||||
// If the authorization fails, we will need to restart reading
|
// If the authorization fails, we will need to restart reading
|
||||||
// from the passed body stream.
|
// from the passed body stream.
|
||||||
// When body is seekable, use seek to reset the streams
|
// 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 {
|
if _, err = sk.Seek(0, io.SeekStart); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
retryBuf = body
|
|
||||||
} else {
|
} else {
|
||||||
buff := &bytes.Buffer{}
|
buff := &bytes.Buffer{}
|
||||||
retryBuf = buff
|
retryBuf = buff
|
||||||
|
Loading…
Reference in New Issue
Block a user