mirror of
https://github.com/rclone/rclone
synced 2024-11-25 02:47:14 +01:00
lib/rest: add CheckRedirect function for redirect management
This commit is contained in:
parent
ff855fe1fb
commit
09cc8179cc
@ -149,6 +149,8 @@ type Opts struct {
|
||||
Trailer *http.Header // set the request trailer
|
||||
Close bool // set to close the connection after this transaction
|
||||
NoRedirect bool // if this is set then the client won't follow redirects
|
||||
// On Redirects, call this function - see the http.Client docs: https://pkg.go.dev/net/http#Client
|
||||
CheckRedirect func(req *http.Request, via []*http.Request) error
|
||||
}
|
||||
|
||||
// Copy creates a copy of the options
|
||||
@ -299,6 +301,10 @@ func (api *Client) Call(ctx context.Context, opts *Opts) (resp *http.Response, e
|
||||
var c *http.Client
|
||||
if opts.NoRedirect {
|
||||
c = ClientWithNoRedirects(api.c)
|
||||
} else if opts.CheckRedirect != nil {
|
||||
clientCopy := *api.c
|
||||
clientCopy.CheckRedirect = opts.CheckRedirect
|
||||
c = &clientCopy
|
||||
} else {
|
||||
c = api.c
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user