From 15d9bb4043b79b1df10258465c60f44b88f19430 Mon Sep 17 00:00:00 2001 From: Erik Pellizzon Date: Fri, 27 Dec 2024 13:19:42 +0100 Subject: [PATCH] Fix ineffective assignment --- websocket.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/websocket.go b/websocket.go index 64bc7405..97108ee5 100644 --- a/websocket.go +++ b/websocket.go @@ -33,14 +33,12 @@ func (proxy *ProxyHttpServer) serveWebsocketTLS( tlsConfig *tls.Config, clientConn *tls.Conn, ) { + host := req.URL.Host // Port is optional in req.URL.Host, in this case SplitHostPort returns // an error, and we add the default port - host, port, err := net.SplitHostPort(req.URL.Host) + _, port, err := net.SplitHostPort(req.URL.Host) if err != nil || port == "" { host = net.JoinHostPort(req.URL.Host, "443") - } else { - // We already had a port, just use it - host = req.URL.Host } targetURL := url.URL{Scheme: "wss", Host: host, Path: req.URL.Path} @@ -68,14 +66,12 @@ func (proxy *ProxyHttpServer) serveWebsocketHttpOverTLS( req *http.Request, clientConn *tls.Conn, ) { + host := req.URL.Host // Port is optional in req.URL.Host, in this case SplitHostPort returns // an error, and we add the default port - host, port, err := net.SplitHostPort(req.URL.Host) + _, port, err := net.SplitHostPort(req.URL.Host) if err != nil || port == "" { host = net.JoinHostPort(req.URL.Host, "80") - } else { - // We already had a port, just use it - host = req.URL.Host } targetURL := url.URL{Scheme: "ws", Host: host, Path: req.URL.Path}