SensitiveHeadersRedirectPolicy strips the given sensitive headers when the redirect target is a different domain. This is useful for custom authentication headers (e.g. "X-API-Key", "X-Auth-Token") that are not automatically stripped by the standard library on cross-domain redirects. By default, Go
(headers ...string)
| 147 | // |
| 148 | // client.SetRedirectPolicy(req.SensitiveHeadersRedirectPolicy("X-API-Key", "X-Auth-Token")) |
| 149 | func SensitiveHeadersRedirectPolicy(headers ...string) RedirectPolicy { |
| 150 | return func(req *http.Request, via []*http.Request) error { |
| 151 | if len(via) == 0 { |
| 152 | return nil |
| 153 | } |
| 154 | // Only strip headers when redirecting to a different domain. |
| 155 | if getDomain(req.URL.Host) == getDomain(via[0].URL.Host) { |
| 156 | return nil |
| 157 | } |
| 158 | for _, header := range headers { |
| 159 | req.Header.Del(header) |
| 160 | } |
| 161 | return nil |
| 162 | } |
| 163 | } |
searching dependent graphs…