From 97987794f9c7ad5dd1c5c56d56eb618c8ecfb498 Mon Sep 17 00:00:00 2001 From: andig Date: Thu, 7 Jan 2021 16:49:46 +0100 Subject: [PATCH] Don't redirect requests from localhost to HTTPS (#78) --- httpsredirect.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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