1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-21 11:57:02 +00:00

iris.TLS starts a secondary http redirection server now (like AutoTLS did) and add 'iris.TLSNoRedirect' to disable it (on both TLS and AutoTLS)

Former-commit-id: c7a535bf860a67604de3d09ade30599611e096f1
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-05-08 21:13:12 +03:00
parent 116503a9a5
commit b6a36bf28d
7 changed files with 168 additions and 86 deletions

View File

@@ -84,6 +84,19 @@ func NewProxy(hostAddr string, target *url.URL) *Supervisor {
// r := NewRedirection(":80", target, 307)
// r.ListenAndServe() // use of `r.Shutdown` to close this server.
func NewRedirection(hostAddr string, target *url.URL, redirectStatus int) *Supervisor {
redirectSrv := &http.Server{
ReadTimeout: 30 * time.Second,
WriteTimeout: 60 * time.Second,
Addr: hostAddr,
Handler: RedirectHandler(target, redirectStatus),
}
return New(redirectSrv)
}
// RedirectHandler returns a simple redirect handler.
// See `NewProxy` or `ProxyHandler` for more features.
func RedirectHandler(target *url.URL, redirectStatus int) http.Handler {
targetURI := target.String()
if redirectStatus <= 300 {
// here we should use StatusPermanentRedirect but
@@ -96,18 +109,11 @@ func NewRedirection(hostAddr string, target *url.URL, redirectStatus int) *Super
redirectStatus = http.StatusTemporaryRedirect
}
redirectSrv := &http.Server{
ReadTimeout: 30 * time.Second,
WriteTimeout: 60 * time.Second,
Addr: hostAddr,
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
redirectTo := singleJoiningSlash(targetURI, r.URL.Path)
if len(r.URL.RawQuery) > 0 {
redirectTo += "?" + r.URL.RawQuery
}
http.Redirect(w, r, redirectTo, redirectStatus)
}),
}
return New(redirectSrv)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
redirectTo := singleJoiningSlash(targetURI, r.URL.Path)
if len(r.URL.RawQuery) > 0 {
redirectTo += "?" + r.URL.RawQuery
}
http.Redirect(w, r, redirectTo, redirectStatus)
})
}