From a992a910ef9b71bd9886aa710086b4aa7bdffdc1 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 26 Aug 2019 12:18:36 +0100 Subject: [PATCH] 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. --- lib/rest/rest.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rest/rest.go b/lib/rest/rest.go index dd0b3004d..0796c3e43 100644 --- a/lib/rest/rest.go +++ b/lib/rest/rest.go @@ -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.