From 7831238375acd8743f621da4e75341aa97d6ed66 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 4 Oct 2020 18:10:11 +0200 Subject: [PATCH] Don't split domain if we use standard HTTP ports --- web/handler.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/web/handler.go b/web/handler.go index b9a61c2..ea7b7ed 100644 --- a/web/handler.go +++ b/web/handler.go @@ -7,6 +7,7 @@ import ( "log" "net" "net/http" + "strings" "github.com/markbates/pkger" "gitlab.crans.org/nounous/ghostream/internal/monitoring" @@ -49,10 +50,14 @@ func viewerGetHandler(w http.ResponseWriter, r *http.Request) { // Get stream ID from URL, or from domain name path := r.URL.Path[1:] if cfg.OneStreamPerDomain { - host, _, err := net.SplitHostPort(r.Host) - if err != nil { - log.Printf("Failed to split host and port from %s", r.Host) - return + var host = r.Host + if strings.Contains(host, ":") { + realHost, _, err := net.SplitHostPort(r.Host) + if err != nil { + log.Printf("Failed to split host and port from %s", r.Host) + return + } + host = realHost } path = host }