diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-01-19 21:08:09 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-01-19 21:08:09 +0530 |
commit | 6663f28f0de308c9365b360cd8ad9ee9e43127ee (patch) | |
tree | 184ee22c9561ce7fd6a62ef6552f8a986f4ba1e7 /components/net/websocket_loader.rs | |
parent | 77d3fbcca3c6f7e8b4068f89e25b090977fe5672 (diff) | |
parent | 482d23bb19568b8a46d83a1c6e8ffb5612a7e605 (diff) | |
download | servo-6663f28f0de308c9365b360cd8ad9ee9e43127ee.tar.gz servo-6663f28f0de308c9365b360cd8ad9ee9e43127ee.zip |
Auto merge of #9358 - jsanders:refactor-websocket-closing, r=jdm
Clean up websocket closing code
Fixes #7860.
This also changes quite a bit about how close codes are implemented, I believe bringing them closer in line with the spec. Instead of saving off the close code sent by the client, it uses the code from the server's closing handshake. It also handles `NO_STATUS` in what I believe is the correct manner. Making this work required a change to the test harness to make the `/echo` websocket handler echo the code sent by the client and handle `NO_STATUS` properly, rather than always replying with `NORMAL`.
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9358)
<!-- Reviewable:end -->
Diffstat (limited to 'components/net/websocket_loader.rs')
-rw-r--r-- | components/net/websocket_loader.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/components/net/websocket_loader.rs b/components/net/websocket_loader.rs index 461972b35f0..e25d7e7389f 100644 --- a/components/net/websocket_loader.rs +++ b/components/net/websocket_loader.rs @@ -71,7 +71,7 @@ pub fn init(connect: WebSocketCommunicate, connect_data: WebSocketConnectData) { Ok(net_url) => net_url, Err(e) => { debug!("Failed to establish a WebSocket connection: {:?}", e); - let _ = connect.event_sender.send(WebSocketNetworkEvent::Close); + let _ = connect.event_sender.send(WebSocketNetworkEvent::Fail); return; } }; @@ -87,7 +87,7 @@ pub fn init(connect: WebSocketCommunicate, connect_data: WebSocketConnectData) { }, Err(e) => { debug!("Failed to establish a WebSocket connection: {:?}", e); - let _ = connect.event_sender.send(WebSocketNetworkEvent::Close); + let _ = connect.event_sender.send(WebSocketNetworkEvent::Fail); return; } @@ -114,7 +114,9 @@ pub fn init(connect: WebSocketCommunicate, connect_data: WebSocketConnectData) { Type::Pong => continue, Type::Close => { ws_sender_incoming.lock().unwrap().send_message(&message).unwrap(); - let _ = resource_event_sender.send(WebSocketNetworkEvent::Close); + let code = message.cd_status_code; + let reason = String::from_utf8_lossy(&message.payload).into_owned(); + let _ = resource_event_sender.send(WebSocketNetworkEvent::Close(code, reason)); break; }, }; @@ -134,8 +136,11 @@ pub fn init(connect: WebSocketCommunicate, connect_data: WebSocketConnectData) { ws_sender_outgoing.lock().unwrap().send_message(&Message::binary(data)).unwrap(); }, WebSocketDomAction::Close(code, reason) => { - ws_sender_outgoing.lock().unwrap() - .send_message(&Message::close_because(code, reason)).unwrap(); + let message = match code { + Some(code) => Message::close_because(code, reason.unwrap_or("".to_owned())), + None => Message::close() + }; + ws_sender_outgoing.lock().unwrap().send_message(&message).unwrap(); }, } } |