websocket: get port of the uri (#6750)

pull/6751/head
Carlos Esquerdo Bernat 2020-11-05 06:36:50 +01:00 committed by GitHub
parent ca8d23acab
commit 8157f3c6ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -444,15 +444,21 @@ fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []b
} }
// parse_uri, parses the url string to it's components // parse_uri, parses the url string to it's components
// todo: support not using port to default ones
fn parse_uri(url string) ?&Uri { fn parse_uri(url string) ?&Uri {
u := urllib.parse(url)? u := urllib.parse(url)?
v := u.request_uri().split('?') v := u.request_uri().split('?')
port := if u.str().starts_with('ws://') {
'80'
} else if u.str().starts_with('wss://') {
'443'
} else {
u.port()
}
querystring := if v.len > 1 { '?' + v[1] } else { '' } querystring := if v.len > 1 { '?' + v[1] } else { '' }
return &Uri{ return &Uri{
url: url url: url
hostname: u.hostname() hostname: u.hostname()
port: u.port() port: port
resource: v[0] resource: v[0]
querystring: querystring querystring: querystring
} }