diff --git a/httpsredirect.go b/httpsredirect.go index 8d101fa..d1025b3 100644 --- a/httpsredirect.go +++ b/httpsredirect.go @@ -1,9 +1,18 @@ package gokrazy -import "net/http" +import ( + "net" + "net/http" +) -// TODO: Configurable https-port func httpsRedirect(w http.ResponseWriter, r *http.Request) { + host, _, _ := net.SplitHostPort(r.RemoteAddr) + ip := net.ParseIP(host) + if ip.IsLoopback() { + http.DefaultServeMux.ServeHTTP(w, r) + return + } + r.URL.Host = r.Host r.URL.Scheme = "https" http.Redirect(w, r, r.URL.String(), http.StatusFound) // Redirect to https