From a9adb42343df447e74071f55e408966b073f0419 Mon Sep 17 00:00:00 2001 From: "Adam Bezecny (DHL IT Services)" Date: Fri, 27 Nov 2020 21:38:33 +0100 Subject: [PATCH] server_allow_unmasked changed from Option to bool --- examples/srv_accept_unmasked_frames.rs | 2 +- src/protocol/mod.rs | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/examples/srv_accept_unmasked_frames.rs b/examples/srv_accept_unmasked_frames.rs index 04acbfc..3710803 100644 --- a/examples/srv_accept_unmasked_frames.rs +++ b/examples/srv_accept_unmasked_frames.rs @@ -34,7 +34,7 @@ fn main() { // This is not in compliance with RFC 6455 but might be handy in some // rare cases where it is necessary to integrate with existing/legacy // clients which are sending unmasked frames - server_allow_unmasked: Some(true), + server_allow_unmasked: true, }); let mut websocket = accept_hdr_with_config(stream.unwrap(), callback, config).unwrap(); diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 6714005..e9730e8 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -54,7 +54,7 @@ pub struct WebSocketConfig { /// Even though this behaviour is not in compliance with RFC 6455 (which requires the server /// to close the connection when unmasked frame from client is received) it might be handy in some cases /// as there are existing applications sending unmasked client frames. - pub server_allow_unmasked: Option, + pub server_allow_unmasked: bool, } impl Default for WebSocketConfig { @@ -63,7 +63,7 @@ impl Default for WebSocketConfig { max_send_queue: None, max_message_size: Some(64 << 20), max_frame_size: Some(16 << 20), - server_allow_unmasked: None, + server_allow_unmasked: false, } } } @@ -457,16 +457,8 @@ impl WebSocketContext { // frame that is not masked. (RFC 6455) // The only exception here is if the user explicitly accepts given // stream (by tungstenite::server::accept_with_config or tungstenite::server::accept_hdr_with_config) - // with WebSocketConfig.server_allow_unmasked set to Some(true) - if let Some(server_allow_unmasked_val) = - self.get_config().server_allow_unmasked - { - if server_allow_unmasked_val == false { - return Err(Error::Protocol( - "Received an unmasked frame from client".into(), - )); - } - } else { + // with WebSocketConfig.server_allow_unmasked set to true + if self.get_config().server_allow_unmasked == false { return Err(Error::Protocol( "Received an unmasked frame from client".into(), ));