mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
WebSocket constructor should not panic
Make an early return when the WebSocket connection fails in the constructor. Also let the WebSockect connection to be closed when the connection could not be established. Fixes #6082.
This commit is contained in:
parent
74ef31cfc4
commit
877c369e0b
25 changed files with 557 additions and 41 deletions
|
@ -141,7 +141,16 @@ impl WebSocket {
|
|||
|
||||
// TODO Client::connect does not conform to RFC 6455
|
||||
// see https://github.com/cyderize/rust-websocket/issues/38
|
||||
let request = Client::connect(parsed_url).unwrap();
|
||||
let request = match Client::connect(parsed_url) {
|
||||
Ok(request) => request,
|
||||
Err(_) => {
|
||||
let global_root = ws_root.global.root();
|
||||
let address = Trusted::new(global_root.r().get_cx(), ws_root, global_root.r().script_chan().clone());
|
||||
let task = box WebSocketTaskHandler::new(address, WebSocketTask::Close);
|
||||
global_root.r().script_chan().send(ScriptMsg::RunnableMsg(task)).unwrap();
|
||||
return Ok(Temporary::from_rooted(ws_root));
|
||||
}
|
||||
};
|
||||
let response = request.send().unwrap();
|
||||
response.validate().unwrap();
|
||||
ws_root.ready_state.set(WebSocketRequestState::Open);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue