From b7172f46cd01fd394c9ee221716f0554cbd1d060 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Wed, 3 Jul 2024 10:57:28 +0200 Subject: redirect to same host even if it doesn't have a port --- internal/server/tls.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'internal/server') 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) -- cgit 1.4.1