mirror of
https://github.com/rclone/rclone
synced 2024-11-27 05:23:40 +01:00
rest: don't canonicalise headers starting with *
This leaves a way of adding headers which shouldn't be canonicalised.
This commit is contained in:
parent
5403e1c79a
commit
65071599a2
@ -75,6 +75,7 @@ func (api *Client) SetRoot(RootURL string) *Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetHeader sets a header for all requests
|
// SetHeader sets a header for all requests
|
||||||
|
// Start the key with "*" for don't canonicalise
|
||||||
func (api *Client) SetHeader(key, value string) *Client {
|
func (api *Client) SetHeader(key, value string) *Client {
|
||||||
api.mu.Lock()
|
api.mu.Lock()
|
||||||
defer api.mu.Unlock()
|
defer api.mu.Unlock()
|
||||||
@ -133,9 +134,9 @@ type Opts struct {
|
|||||||
ContentType string
|
ContentType string
|
||||||
ContentLength *int64
|
ContentLength *int64
|
||||||
ContentRange string
|
ContentRange string
|
||||||
ExtraHeaders map[string]string
|
ExtraHeaders map[string]string // extra headers, start them with "*" for don't canonicalise
|
||||||
UserName string // username for Basic Auth
|
UserName string // username for Basic Auth
|
||||||
Password string // password for Basic Auth
|
Password string // password for Basic Auth
|
||||||
Options []fs.OpenOption
|
Options []fs.OpenOption
|
||||||
IgnoreStatus bool // if set then we don't check error status or parse error body
|
IgnoreStatus bool // if set then we don't check error status or parse error body
|
||||||
MultipartParams url.Values // if set do multipart form upload with attached file
|
MultipartParams url.Values // if set do multipart form upload with attached file
|
||||||
@ -247,10 +248,17 @@ func (api *Client) Call(ctx context.Context, opts *Opts) (resp *http.Response, e
|
|||||||
fs.OpenOptionAddHeaders(opts.Options, headers)
|
fs.OpenOptionAddHeaders(opts.Options, headers)
|
||||||
// Now set the headers
|
// Now set the headers
|
||||||
for k, v := range headers {
|
for k, v := range headers {
|
||||||
if v != "" {
|
if k != "" && v != "" {
|
||||||
req.Header.Add(k, v)
|
if k[0] == '*' {
|
||||||
|
// Add non-canonical version if header starts with *
|
||||||
|
k = k[1:]
|
||||||
|
req.Header[k] = append(req.Header[k], v)
|
||||||
|
} else {
|
||||||
|
req.Header.Add(k, v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.UserName != "" || opts.Password != "" {
|
if opts.UserName != "" || opts.Password != "" {
|
||||||
req.SetBasicAuth(opts.UserName, opts.Password)
|
req.SetBasicAuth(opts.UserName, opts.Password)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user