From 3a8066f10b923f3aeecece5714729bb178aa300c Mon Sep 17 00:00:00 2001 From: Matt Brittan Date: Thu, 22 Dec 2022 14:29:23 +1300 Subject: [PATCH] Clear URL User before creating websocket connection (allowing MQTT username/password to be specified in URL) Closes #623 --- netconn.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/netconn.go b/netconn.go index 7e3899e9..8466f993 100644 --- a/netconn.go +++ b/netconn.go @@ -40,10 +40,14 @@ import ( func openConnection(uri *url.URL, tlsc *tls.Config, timeout time.Duration, headers http.Header, websocketOptions *WebsocketOptions, dialer *net.Dialer) (net.Conn, error) { switch uri.Scheme { case "ws": - conn, err := NewWebsocket(uri.String(), nil, timeout, headers, websocketOptions) + dialURI := uri // #623 - Gorilla Websockets does not accept URL's where uri.User != nil + uri.User = nil + conn, err := NewWebsocket(dialURI.String(), nil, timeout, headers, websocketOptions) return conn, err case "wss": - conn, err := NewWebsocket(uri.String(), tlsc, timeout, headers, websocketOptions) + dialURI := uri // #623 - Gorilla Websockets does not accept URL's where uri.User != nil + uri.User = nil + conn, err := NewWebsocket(dialURI.String(), tlsc, timeout, headers, websocketOptions) return conn, err case "mqtt", "tcp": allProxy := os.Getenv("all_proxy")