mirror of
https://github.com/servo/servo.git
synced 2025-07-05 22:43:40 +01:00
Auto merge of #8693 - yanirs:websocket-close-unspecified-status, r=jdm
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 -->
This commit is contained in:
commit
01b4deb9d1
2 changed files with 21 additions and 10 deletions
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
[Secure-Close-1005-verify-code.htm]
|
||||
type: testharness
|
||||
[W3C WebSocket API - Create Secure WebSocket - Close the Connection - close() - return close code is 1005 - Connection should be closed]
|
||||
expected: FAIL
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue