rest: use readers.NoCloser to stop body being closed

Before this change, if you passed a io.ReadCloser to opt.Body then the
transaction would close it.  This happens as part of http.NewRequest
which documents that the io.Reader passed in will be upgraded to a
Closer if possible and closed as part of the Do call.

After this change, we wrap any io.ReadClosers to stop them being
upgraded.  This means that they will never get closed and that the
caller should always close them.

This fixes a panic in the googlephotos integration tests.
s3-about
Nick Craig-Wood 2019-08-26 12:18:36 +01:00
parent ce3340621f
commit a992a910ef
1 changed files with 2 additions and 1 deletions

View File

@ -16,6 +16,7 @@ import (
"github.com/pkg/errors"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/lib/readers"
)
// Client contains the info to sustain the API
@ -198,7 +199,7 @@ func (api *Client) Call(opts *Opts) (resp *http.Response, err error) {
if opts.Parameters != nil && len(opts.Parameters) > 0 {
url += "?" + opts.Parameters.Encode()
}
body := opts.Body
body := readers.NoCloser(opts.Body)
// If length is set and zero then nil out the body to stop use
// use of chunked encoding and insert a "Content-Length: 0"
// header.