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

Function SensitiveHeadersRedirectPolicy

redirect.go:149–163  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

147//
148// client.SetRedirectPolicy(req.SensitiveHeadersRedirectPolicy("X-API-Key", "X-Auth-Token"))
149func 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}

Callers 1

Calls 1

getDomainFunction · 0.85

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…