Don't redirect requests from localhost to HTTPS (#78)

This commit is contained in:
andig 2021-01-07 16:49:46 +01:00 committed by GitHub
parent 5fc5d0ab5d
commit 97987794f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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