mirror of
https://github.com/rclone/rclone.git
synced 2024-12-22 23:22:08 +01:00
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.
This commit is contained in:
parent
ce3340621f
commit
a992a910ef
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user