| 127 | var HostsRedirectCode = iris.StatusMovedPermanently |
| 128 | |
| 129 | func 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 | } |