Skip to content

Commit

Permalink
Auto merge of #8693 - yanirs:websocket-close-unspecified-status, r=jdm
Browse files Browse the repository at this point in the history
Implement unspecified websocket close code (fixes issue #8158)

Fixes #8158.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8693)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Dec 3, 2015
2 parents 20df7fb + ad9accf commit 01b4deb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
26 changes: 21 additions & 5 deletions components/script/dom/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ const BLOCKED_PORTS_LIST: &'static [u16] = &[
6000, // x11
];

// Close codes defined in https://tools.ietf.org/html/rfc6455#section-7.4.1
// Names are from https://github.com/mozilla/gecko-dev/blob/master/netwerk/protocol/websocket/nsIWebSocketChannel.idl
#[allow(dead_code)]
mod close_code {
pub const NORMAL: u16 = 1000;
pub const GOING_AWAY: u16 = 1001;
pub const PROTOCOL_ERROR: u16 = 1002;
pub const UNSUPPORTED_DATATYPE: u16 = 1003;
pub const NO_STATUS: u16 = 1005;
pub const ABNORMAL: u16 = 1006;
pub const INVALID_PAYLOAD: u16 = 1007;
pub const POLICY_VIOLATION: u16 = 1008;
pub const TOO_LARGE: u16 = 1009;
pub const EXTENSION_MISSING: u16 = 1010;
pub const INTERNAL_ERROR: u16 = 1011;
pub const TLS_FAILED: u16 = 1015;
}

#[dom_struct]
pub struct WebSocket {
eventtarget: EventTarget,
Expand Down Expand Up @@ -430,8 +448,8 @@ impl WebSocketMethods for WebSocket {


if let Some(code) = code {
//Check code is NOT 1000 NOR in the range of 3000-4999 (inclusive)
if code != 1000 && (code < 3000 || code > 4999) {
//Fail if the supplied code isn't normal and isn't reserved for libraries, frameworks, and applications
if code != close_code::NORMAL && (code < 3000 || code > 4999) {
return Err(Error::InvalidAccess);
}
}
Expand All @@ -454,9 +472,7 @@ impl WebSocketMethods for WebSocket {
WebSocketRequestState::Open => {
//Closing handshake not started - still in open
//Start the closing by setting the code and reason if they exist
if let Some(code) = code {
self.code.set(code);
}
self.code.set(code.unwrap_or(close_code::NO_STATUS));
if let Some(reason) = reason {
*self.reason.borrow_mut() = reason.0;
}
Expand Down

This file was deleted.

0 comments on commit 01b4deb

Please sign in to comment.