MCPcopy Create free account
hub / github.com/kataras/iris / newHostRedirectApp

Function newHostRedirectApp

apps/switch_hosts.go:129–148  ·  view source on GitHub ↗
(targetHost string, code int)

Source from the content-addressed store, hash-verified

127var HostsRedirectCode = iris.StatusMovedPermanently
128
129func newHostRedirectApp(targetHost string, code int) *iris.Application {
130 app := iris.New()
131 app.Downgrade(func(w http.ResponseWriter, r *http.Request) {
132 if targetHost == context.GetHost(r) {
133 // Note(@kataras):
134 // this should never happen as the HostsRedirect
135 // carefully checks if the expression already matched the "redirectTo"
136 // to avoid the redirect loops at all.
137 // iris: switch: hosts redirect: loop detected between expression: "^my.*$" and target host: "mydomain.com"
138 http.Error(w, iris.StatusText(iris.StatusTooManyRequests), iris.StatusTooManyRequests)
139 return
140 }
141
142 r.Host = targetHost
143 r.URL.Host = targetHost
144 // r.URL.User = nil
145 http.Redirect(w, r, r.URL.String(), code)
146 })
147 return app
148}

Callers 1

hostAppFunction · 0.85

Calls 6

GetHostFunction · 0.92
NewMethod · 0.80
DowngradeMethod · 0.80
RedirectMethod · 0.80
ErrorMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…