minor fixes

pull/159/head
Adam Bezecny (DHL IT Services) 4 years ago
parent 4f7dab5d7b
commit 9f292d21fc
  1. 2
      examples/srv_accept_unmasked_frames.rs
  2. 19
      src/protocol/mod.rs

@ -34,7 +34,7 @@ fn main() {
// This is not in compliance with RFC 6455 but might be handy in some // 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 // rare cases where it is necessary to integrate with existing/legacy
// clients which are sending unmasked frames // clients which are sending unmasked frames
server_allow_unmasked: true, accept_unmasked_frames: true,
}); });
let mut websocket = accept_hdr_with_config(stream.unwrap(), callback, config).unwrap(); let mut websocket = accept_hdr_with_config(stream.unwrap(), callback, config).unwrap();

@ -50,13 +50,12 @@ pub struct WebSocketConfig {
/// be reasonably big for all normal use-cases but small enough to prevent memory eating /// be reasonably big for all normal use-cases but small enough to prevent memory eating
/// by a malicious user. /// by a malicious user.
pub max_frame_size: Option<usize>, pub max_frame_size: Option<usize>,
/// If set to true it will allow the websocket server to accept unmasked frames from client. /// When set to `true`, the server will accept and handle unmasked frames
/// Even though this behaviour is not in compliance with RFC 6455 (which requires the server /// from the client. According to the RFC 6455, the server must close the
/// to close the connection when unmasked frame from client is received) it might be handy in some cases /// connection to the client in such cases, however it seems like there are
/// as there are existing applications sending unmasked client frames. By default (i.e. unless not explicitly specified) /// some popular libraries that are sending unmasked frames, ignoring the RFC.
/// this flag is set to false which means violation of RFC 6455 is not allowed and unmasked client frames will be rejected /// By default this option is set to `false`, i.e. according to RFC 6455.
///by websocket server. pub accept_unmasked_frames: bool,
pub server_allow_unmasked: bool,
} }
impl Default for WebSocketConfig { impl Default for WebSocketConfig {
@ -65,7 +64,7 @@ impl Default for WebSocketConfig {
max_send_queue: None, max_send_queue: None,
max_message_size: Some(64 << 20), max_message_size: Some(64 << 20),
max_frame_size: Some(16 << 20), max_frame_size: Some(16 << 20),
server_allow_unmasked: false, accept_unmasked_frames: false,
} }
} }
} }
@ -459,8 +458,8 @@ impl WebSocketContext {
// frame that is not masked. (RFC 6455) // frame that is not masked. (RFC 6455)
// The only exception here is if the user explicitly accepts given // 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) // stream (by tungstenite::server::accept_with_config or tungstenite::server::accept_hdr_with_config)
// with WebSocketConfig.server_allow_unmasked set to true // with WebSocketConfig.accept_unmasked_frames set to true
if self.get_config().server_allow_unmasked == false { if !self.config.accept_unmasked_frames {
return Err(Error::Protocol( return Err(Error::Protocol(
"Received an unmasked frame from client".into(), "Received an unmasked frame from client".into(),
)); ));

Loading…
Cancel
Save