lib/rest: add CheckRedirect function for redirect management
This commit is contained in:
parent
ff855fe1fb
commit
09cc8179cc
1 changed files with 6 additions and 0 deletions
|
@ -149,6 +149,8 @@ type Opts struct {
|
||||||
Trailer *http.Header // set the request trailer
|
Trailer *http.Header // set the request trailer
|
||||||
Close bool // set to close the connection after this transaction
|
Close bool // set to close the connection after this transaction
|
||||||
NoRedirect bool // if this is set then the client won't follow redirects
|
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
|
// 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
|
var c *http.Client
|
||||||
if opts.NoRedirect {
|
if opts.NoRedirect {
|
||||||
c = ClientWithNoRedirects(api.c)
|
c = ClientWithNoRedirects(api.c)
|
||||||
|
} else if opts.CheckRedirect != nil {
|
||||||
|
clientCopy := *api.c
|
||||||
|
clientCopy.CheckRedirect = opts.CheckRedirect
|
||||||
|
c = &clientCopy
|
||||||
} else {
|
} else {
|
||||||
c = api.c
|
c = api.c
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue