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

Function AlwaysCopyHeaderRedirectPolicy

redirect.go:121–134  ·  view source on GitHub ↗

AlwaysCopyHeaderRedirectPolicy ensures that the given sensitive headers will always be copied on redirect. By default, golang will copy all of the original request's headers on redirect, unless they're sensitive, like "Authorization" or "Www-Authenticate". Only send sensitive ones to the same origin

(headers ...string)

Source from the content-addressed store, hash-verified

119//
120// client.SetRedirectPolicy(req.AlwaysCopyHeaderRedirectPolicy("Authorization"))
121func AlwaysCopyHeaderRedirectPolicy(headers ...string) RedirectPolicy {
122 return func(req *http.Request, via []*http.Request) error {
123 for _, header := range headers {
124 if len(req.Header.Values(header)) > 0 {
125 continue
126 }
127 vals := via[0].Header.Values(header)
128 for _, val := range vals {
129 req.Header.Add(header, val)
130 }
131 }
132 return nil
133 }
134}
135
136// SensitiveHeadersRedirectPolicy strips the given sensitive headers when the
137// redirect target is a different domain. This is useful for custom authentication

Callers 1

TestRedirectFunction · 0.85

Calls 1

AddMethod · 0.80

Tested by 1

TestRedirectFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…