mirror of
https://github.com/fosrl/newt.git
synced 2026-05-14 12:19:53 +00:00
Try to add redirect
This commit is contained in:
@@ -336,6 +336,19 @@ func (h *HTTPHandler) handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// If the rule is plain HTTP but has a TLS certificate configured, redirect
|
||||
// the client to the HTTPS equivalent of the requested URL.
|
||||
if rule.Protocol == "http" && rule.TLSCert != "" && rule.TLSKey != "" {
|
||||
host := r.Host
|
||||
if host == "" {
|
||||
host = r.URL.Host
|
||||
}
|
||||
httpsURL := "https://" + host + r.RequestURI
|
||||
logger.Info("HTTP handler: redirecting %s %s -> %s (TLS cert present)", r.Method, r.URL.RequestURI(), httpsURL)
|
||||
http.Redirect(w, r, httpsURL, http.StatusMovedPermanently)
|
||||
return
|
||||
}
|
||||
|
||||
target := rule.HTTPTargets[0]
|
||||
scheme := target.Scheme
|
||||
logger.Info("HTTP handler: %s %s -> %s://%s:%d",
|
||||
|
||||
Reference in New Issue
Block a user