MCPcopy Create free account
hub / github.com/imroc/req / SetRedirectPolicy

Method SetRedirectPolicy

client.go:330–350  ·  view source on GitHub ↗

SetRedirectPolicy set the RedirectPolicy which controls the behavior of receiving redirect responses (usually responses with 301 and 302 status code), see the predefined AllowedDomainRedirectPolicy, AllowedHostRedirectPolicy, DefaultRedirectPolicy, MaxRedirectPolicy, NoRedirectPolicy, SameDomainRedi

(policies ...RedirectPolicy)

Source from the content-addressed store, hash-verified

328// AllowedDomainRedirectPolicy, AllowedHostRedirectPolicy, DefaultRedirectPolicy, MaxRedirectPolicy,
329// NoRedirectPolicy, SameDomainRedirectPolicy and SameHostRedirectPolicy.
330func (c *Client) SetRedirectPolicy(policies ...RedirectPolicy) *Client {
331 if len(policies) == 0 {
332 return c
333 }
334 c.httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
335 for _, f := range policies {
336 if f == nil {
337 continue
338 }
339 err := f(req, via)
340 if err != nil {
341 return err
342 }
343 }
344 if c.DebugLog {
345 c.log.Debugf("<redirect> %s %s", req.Method, req.URL.String())
346 }
347 return nil
348 }
349 return c
350}
351
352// DisableKeepAlives disable the HTTP keep-alives (enabled by default)
353// and will only use the connection to the server for a single

Callers 4

CFunction · 0.95
TestRedirectFunction · 0.80
SetRedirectPolicyFunction · 0.80

Calls 2

DebugfMethod · 0.65
StringMethod · 0.45

Tested by 2

TestRedirectFunction · 0.64