Permalink
Browse files

acd: Reset the headers on tempurl redirect #802

  • Loading branch information...
1 parent 9d2dd2c commit 5986953317a0b1e2387fbad0002e39b3ef19cbd7 @ncw committed Oct 26, 2016
Showing with 6 additions and 4 deletions.
  1. +2 −1 amazonclouddrive/amazonclouddrive.go
  2. +4 −3 rest/rest.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)
})
View
@@ -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()

0 comments on commit 5986953

Please sign in to comment.