inhibit stream close on request

This commit is contained in:
Ringo Hoffmann 2022-01-22 12:29:02 +01:00
parent c01be49bed
commit 2889239999
No known key found for this signature in database
GPG Key ID: 5DE1487DA08E34FE
2 changed files with 15 additions and 0 deletions

View File

@ -14,6 +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.
body = closeInhibitor{body}
// 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

View File

@ -133,3 +133,14 @@ func (l *limitedReadCloser) Read(buf []byte) (int, error) {
func (l *limitedReadCloser) Close() error {
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
}