diff --git a/lib/rest/rest.go b/lib/rest/rest.go index a7bba472b..61522577d 100644 --- a/lib/rest/rest.go +++ b/lib/rest/rest.go @@ -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 }