acd: Reset the headers on tempurl redirect #802

This commit is contained in:
Nick Craig-Wood 2016-10-26 18:42:41 +01:00
parent 9d2dd2c49a
commit 5986953317
2 changed files with 6 additions and 4 deletions

View File

@ -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 File

@ -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()