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)
| 119 | // |
| 120 | // client.SetRedirectPolicy(req.AlwaysCopyHeaderRedirectPolicy("Authorization")) |
| 121 | func 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 |
searching dependent graphs…