From 635c99e2edc8ce385228ec6dcf7db4ea8a11b7c0 Mon Sep 17 00:00:00 2001 From: Carlos Esquerdo Bernat Date: Wed, 22 Jul 2020 16:35:30 +0200 Subject: [PATCH] ws: obtain port when not specified (#5922) --- vlib/net/websocket/ws.v | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/vlib/net/websocket/ws.v b/vlib/net/websocket/ws.v index 673489a84b..96c7e5c291 100644 --- a/vlib/net/websocket/ws.v +++ b/vlib/net/websocket/ws.v @@ -107,10 +107,19 @@ fn (ws &Client) parse_uri() &Uri { panic(err) } v := u.request_uri().split('?') + mut port := u.port() + //Check if port is empty and check protocol to get the port, secure by default + if port == '' { + if ws.uri.contains('://') { + port = if ws.uri.split('://')[0] == 'ws' { '80' } else { '443' } + } else { + port = '443' + } + } querystring := if v.len > 1 { '?' + v[1] } else { '' } return &Uri{ hostname: u.hostname() - port: u.port() + port: port resource: v[0] querystring: querystring }