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
1 files changed, 6 insertions(+), 6 deletions(-)
jump to
M internal/server/tls.go → internal/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)