all repos — website @ b7172f46cd01fd394c9ee221716f0554cbd1d060

My website

redirect to same host even if it doesn't have a port
Alan Pearce alan@alanpearce.eu
Wed, 03 Jul 2024 10:57:28 +0200
commit

b7172f46cd01fd394c9ee221716f0554cbd1d060

parent

80c9717db80d9ead7c0c8a8693475ed0c2150470

1 files changed, 6 insertions(+), 6 deletions(-)

jump to
M internal/server/tls.gointernal/server/tls.go
@@ -105,15 +105,15 @@ return 			}
 			url := r.URL
 			url.Scheme = "https"
-			host, _, err := net.SplitHostPort(r.Host)
-			if err != nil {
-				log.Warn("error splitting host and port", "error", err)
-				host = s.config.BaseURL.Hostname()
-			}
 			port := s.config.BaseURL.Port()
 			if port == "" {
-				url.Host = host
+				url.Host = r.Host
 			} else {
+				host, _, err := net.SplitHostPort(r.Host)
+				if err != nil {
+					log.Warn("error splitting host and port", "error", err)
+					host = r.Host
+				}
 				url.Host = net.JoinHostPort(host, s.config.BaseURL.Port())
 			}
 			http.Redirect(w, r, url.String(), http.StatusMovedPermanently)