mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 08:58:26 +08:00
rest: Add RemoveHeader and SetCookie method
These methods extend the rest package to support the cookie header and header deletion. The deletion is necessary to delete an existing authorization header if cookie auth should be used.
This commit is contained in:
parent
dc59836021
commit
ba7ae2ee8c
|
@ -80,6 +80,14 @@ func (api *Client) SetHeader(key, value string) *Client {
|
|||
return api
|
||||
}
|
||||
|
||||
// RemoveHeader unsets a header for all requests
|
||||
func (api *Client) RemoveHeader(key string) *Client {
|
||||
api.mu.Lock()
|
||||
defer api.mu.Unlock()
|
||||
delete(api.headers, key)
|
||||
return api
|
||||
}
|
||||
|
||||
// SignerFn is used to sign an outgoing request
|
||||
type SignerFn func(*http.Request) error
|
||||
|
||||
|
@ -100,6 +108,19 @@ func (api *Client) SetUserPass(UserName, Password string) *Client {
|
|||
return api
|
||||
}
|
||||
|
||||
// SetCookie creates an Cookies Header for all requests with the supplied
|
||||
// cookies passed in.
|
||||
// All cookies have to be supplied at once, all cookies will be overwritten
|
||||
// on a new call to the method
|
||||
func (api *Client) SetCookie(cks ...*http.Cookie) *Client {
|
||||
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
||||
for _, ck := range cks {
|
||||
req.AddCookie(ck)
|
||||
}
|
||||
api.SetHeader("Cookie", req.Header.Get("Cookie"))
|
||||
return api
|
||||
}
|
||||
|
||||
// Opts contains parameters for Call, CallJSON etc
|
||||
type Opts struct {
|
||||
Method string // GET, POST etc
|
||||
|
|
Loading…
Reference in New Issue
Block a user