mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
x.websocket: fix the uri port parsing problem. Make failures more informative (#6775)
This commit is contained in:
@@ -447,12 +447,15 @@ fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []b
|
||||
fn parse_uri(url string) ?&Uri {
|
||||
u := urllib.parse(url)?
|
||||
v := u.request_uri().split('?')
|
||||
port := if u.str().starts_with('ws://') {
|
||||
'80'
|
||||
} else if u.str().starts_with('wss://') {
|
||||
'443'
|
||||
} else {
|
||||
u.port()
|
||||
mut port := u.port()
|
||||
if port == '' {
|
||||
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 { '' }
|
||||
return &Uri{
|
||||
|
||||
@@ -16,6 +16,7 @@ fn start_server() ? {
|
||||
// Here you can look att the client info and accept or not accept
|
||||
// just returning a true/false
|
||||
if s.resource_name != '/' {
|
||||
panic('unexpected resource name in test')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -61,11 +62,15 @@ fn ws_test(uri string) ? {
|
||||
println('Binary message: $msg')
|
||||
}
|
||||
})
|
||||
ws.connect()
|
||||
ws.connect() or {
|
||||
panic('fail to connect')
|
||||
}
|
||||
go ws.listen()
|
||||
text := ['a'].repeat(2)
|
||||
for msg in text {
|
||||
ws.write(msg.bytes(), .text_frame)?
|
||||
ws.write(msg.bytes(), .text_frame) or {
|
||||
panic('fail to write to websocket')
|
||||
}
|
||||
// sleep to give time to recieve response before send a new one
|
||||
time.sleep_ms(100)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user