mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #6620 - Ms2ger:ws-crash, r=jdm
Stop panicking while establishing a WebSocket connection. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6620) <!-- Reviewable:end -->
This commit is contained in:
commit
d91a6f3834
27 changed files with 44 additions and 71 deletions
|
@ -33,6 +33,7 @@ use websocket::stream::WebSocketStream;
|
||||||
use websocket::client::request::Url;
|
use websocket::client::request::Url;
|
||||||
use websocket::Client;
|
use websocket::Client;
|
||||||
use websocket::header::Origin;
|
use websocket::header::Origin;
|
||||||
|
use websocket::result::WebSocketResult;
|
||||||
|
|
||||||
#[derive(JSTraceable, PartialEq, Copy, Clone)]
|
#[derive(JSTraceable, PartialEq, Copy, Clone)]
|
||||||
enum WebSocketRequestState {
|
enum WebSocketRequestState {
|
||||||
|
@ -101,6 +102,19 @@ fn parse_web_socket_url(url_str: &str) -> Fallible<(Url, String, u16, String, bo
|
||||||
Ok((parsed_url, host, port, resource, secure))
|
Ok((parsed_url, host, port, resource, secure))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// *Establish a WebSocket Connection* as defined in RFC 6455.
|
||||||
|
fn establish_a_websocket_connection(url: Url, origin: String)
|
||||||
|
-> WebSocketResult<(Sender<WebSocketStream>, Receiver<WebSocketStream>)> {
|
||||||
|
let mut request = try!(Client::connect(url));
|
||||||
|
request.headers.set(Origin(origin));
|
||||||
|
|
||||||
|
let response = try!(request.send());
|
||||||
|
try!(response.validate());
|
||||||
|
|
||||||
|
Ok(response.begin().split())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
impl WebSocket {
|
impl WebSocket {
|
||||||
pub fn new_inherited(global: GlobalRef, url: Url) -> WebSocket {
|
pub fn new_inherited(global: GlobalRef, url: Url) -> WebSocket {
|
||||||
WebSocket {
|
WebSocket {
|
||||||
|
@ -138,11 +152,11 @@ impl WebSocket {
|
||||||
global,
|
global,
|
||||||
WebSocketBinding::Wrap);
|
WebSocketBinding::Wrap);
|
||||||
|
|
||||||
// TODO Client::connect does not conform to RFC 6455
|
let channel = establish_a_websocket_connection(url, global.get_url().serialize());
|
||||||
// see https://github.com/cyderize/rust-websocket/issues/38
|
let (temp_sender, temp_receiver) = match channel {
|
||||||
let mut request = match Client::connect(url) {
|
Ok(channel) => channel,
|
||||||
Ok(request) => request,
|
Err(e) => {
|
||||||
Err(_) => {
|
debug!("Failed to establish a WebSocket connection: {:?}", e);
|
||||||
let global_root = ws.r().global.root();
|
let global_root = ws.r().global.root();
|
||||||
let address = Trusted::new(global_root.r().get_cx(), ws.r(), global_root.r().script_chan().clone());
|
let address = Trusted::new(global_root.r().get_cx(), ws.r(), global_root.r().script_chan().clone());
|
||||||
let task = box WebSocketTaskHandler::new(address, WebSocketTask::Close);
|
let task = box WebSocketTaskHandler::new(address, WebSocketTask::Close);
|
||||||
|
@ -150,11 +164,7 @@ impl WebSocket {
|
||||||
return Ok(ws);
|
return Ok(ws);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
request.headers.set(Origin(global.get_url().serialize()));
|
|
||||||
let response = request.send().unwrap();
|
|
||||||
response.validate().unwrap();
|
|
||||||
|
|
||||||
let (temp_sender, temp_receiver) = response.begin().split();
|
|
||||||
*ws.r().sender.borrow_mut() = Some(temp_sender);
|
*ws.r().sender.borrow_mut() = Some(temp_sender);
|
||||||
*ws.r().receiver.borrow_mut() = Some(temp_receiver);
|
*ws.r().receiver.borrow_mut() = Some(temp_receiver);
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
[022.html]
|
[022.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
expected: CRASH
|
expected: TIMEOUT
|
||||||
|
[WebSockets: protocol array]
|
||||||
|
expected: TIMEOUT
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
[bufferedAmount-initial.html]
|
[bufferedAmount-initial.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
expected: CRASH
|
[WebSockets: getting bufferedAmount]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
[bufferedAmount-readonly.html]
|
[bufferedAmount-readonly.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
expected: CRASH
|
[WebSockets: setting bufferedAmount]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
[close-connecting.html]
|
[close-connecting.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
expected: CRASH
|
[WebSockets: close() when connecting]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
[close-replace.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[001.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[002.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[003.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[004.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +1,5 @@
|
||||||
[001.html]
|
[001.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
expected: CRASH
|
[WebSockets: getting on* 1]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
[002.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[003.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[004.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +1,5 @@
|
||||||
[006.html]
|
[006.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
expected: CRASH
|
[WebSockets: 'on*' in ws]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
[007.html]
|
[007.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
expected: CRASH
|
[WebSockets: listening for events with onmessage]
|
||||||
|
expected: TIMEOUT
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
[008.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[009.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[001.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[002.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[002.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[001.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[002.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[003.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +0,0 @@
|
||||||
[004.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
|
@ -1,3 +1,5 @@
|
||||||
[001.html]
|
[001.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
expected: CRASH
|
[WebSockets: invalid handshake]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
[001.html]
|
|
||||||
type: testharness
|
|
||||||
expected: CRASH
|
|
Loading…
Add table
Add a link
Reference in a new issue