Compare commits

...

4 Commits

Author SHA1 Message Date
Ringo Hoffmann
0d8627db50
Re-add setting requestBuf after seeking 2022-01-28 17:24:17 +01:00
Ringo Hoffmann
c42caf78a2
update doucmentaiton comment 2022-01-28 17:19:52 +01:00
Ringo Hoffmann
341db84788
close closable body after request 2022-01-28 17:06:32 +01:00
Ringo Hoffmann
b51247bb2c
inhibit stream close on request 2022-01-28 16:31:16 +01:00
2 changed files with 20 additions and 0 deletions

View File

@ -14,6 +14,15 @@ 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
// will fail on retry because stream is already closed.
// This inhibits the closing of the passed stream on passing
// it to the RoundTripper and closes the stream after we
// are done with the body content.
if cl, ok := body.(io.Closer); ok {
body = closeInhibitor{body}
defer cl.Close()
}
// 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

View File

@ -133,3 +133,14 @@ func (l *limitedReadCloser) Read(buf []byte) (int, error) {
func (l *limitedReadCloser) Close() error { func (l *limitedReadCloser) Close() error {
return l.rc.Close() return l.rc.Close()
} }
// closeInhibitor implements io.Closer and
// wraps a Reader. When Close() is performed
// on it, it will simply be silently rejected.
type closeInhibitor struct {
io.Reader
}
func (ci closeInhibitor) Close() error {
return nil
}