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
1 changed files with 13 additions and 5 deletions
|
@ -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,7 +134,7 @@ 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
|
||||||
|
@ -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 != "" {
|
||||||
|
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)
|
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 a new issue