about summary refs log tree commit diff stats
path: root/internal/server
diff options
context:
space:
mode:
authorAlan Pearce2024-07-03 10:57:28 +0200
committerAlan Pearce2024-07-03 10:57:28 +0200
commitb7172f46cd01fd394c9ee221716f0554cbd1d060 (patch)
treece932e48ca4f17801b3ffba8c321e1763b8fb7b2 /internal/server
parent80c9717db80d9ead7c0c8a8693475ed0c2150470 (diff)
downloadwebsite-b7172f46cd01fd394c9ee221716f0554cbd1d060.tar.lz
website-b7172f46cd01fd394c9ee221716f0554cbd1d060.tar.zst
website-b7172f46cd01fd394c9ee221716f0554cbd1d060.zip
redirect to same host even if it doesn't have a port
Diffstat (limited to 'internal/server')
-rw-r--r--internal/server/tls.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/internal/server/tls.go b/internal/server/tls.go
index 71dde54..85eaac9 100644
--- a/internal/server/tls.go
+++ b/internal/server/tls.go
@@ -105,15 +105,15 @@ func (s *Server) serveTLS() (err error) {
 			}
 			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)