Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

acd: Reset the headers on tempurl redirect #802

Nick Craig-Wood5986953317a0
diff --git a/amazonclouddrive/amazonclouddrive.go b/amazonclouddrive/amazonclouddrive.go
index 065a93ba3..595068c4e 100644
--- a/amazonclouddrive/amazonclouddrive.go
+++ b/amazonclouddrive/amazonclouddrive.go
@@ -27,6 +27,7 @@ import (
"github.com/ncw/rclone/fs"
"github.com/ncw/rclone/oauthutil"
"github.com/ncw/rclone/pacer"
+ "github.com/ncw/rclone/rest"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"golang.org/x/oauth2"
@@ -811,7 +812,7 @@ func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) {
if !bigObject {
in, resp, err = file.OpenHeaders(headers)
} else {
- in, resp, err = file.OpenTempURLHeaders(o.fs.noAuthClient, headers)
+ in, resp, err = file.OpenTempURLHeaders(rest.ClientWithHeaderReset(o.fs.noAuthClient, headers), headers)
}
return o.fs.shouldRetry(resp, err)
})
diff --git a/rest/rest.go b/rest/rest.go
index 5907074c0..d3105b6b3 100644
--- a/rest/rest.go
+++ b/rest/rest.go
@@ -93,8 +93,9 @@ func DecodeJSON(resp *http.Response, result interface{}) (err error) {
return decoder.Decode(result)
}
-// Make a new http client which resets the headers passed in on redirect
-func clientWithHeaderReset(c *http.Client, headers map[string]string) *http.Client {
+// ClientWithHeaderReset makes a new http client which resets the
+// headers passed in on redirect
+func ClientWithHeaderReset(c *http.Client, headers map[string]string) *http.Client {
if len(headers) == 0 {
return c
}
@@ -169,7 +170,7 @@ func (api *Client) Call(opts *Opts) (resp *http.Response, err error) {
if opts.UserName != "" || opts.Password != "" {
req.SetBasicAuth(opts.UserName, opts.Password)
}
- c := clientWithHeaderReset(api.c, headers)
+ c := ClientWithHeaderReset(api.c, headers)
api.mu.RUnlock()
resp, err = c.Do(req)
api.mu.RLock()