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

Function SameHostRedirectPolicy

redirect.go:51–58  ·  view source on GitHub ↗

SameHostRedirectPolicy allows redirect only if the redirected host is the same as original host, e.g. redirect to "www.imroc.cc" from "imroc.cc" is not the allowed.

()

Source from the content-addressed store, hash-verified

49// is the same as original host, e.g. redirect to "www.imroc.cc" from
50// "imroc.cc" is not the allowed.
51func SameHostRedirectPolicy() RedirectPolicy {
52 return func(req *http.Request, via []*http.Request) error {
53 if getHostname(req.URL.Host) != getHostname(via[0].URL.Host) {
54 return errors.New("different host name is not allowed")
55 }
56 return nil
57 }
58}
59
60// AllowedHostRedirectPolicy allows redirect only if the redirected host
61// match one of the host that specified.

Callers 1

TestRedirectFunction · 0.85

Calls 1

getHostnameFunction · 0.85

Tested by 1

TestRedirectFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…