diff --git a/src/config.rs b/src/config.rs index 71ecf7b..62121b8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -42,6 +42,8 @@ pub struct Config { pub backpressure: usize, #[serde(default = "default_validate_token")] pub validate_token: bool, + #[serde(default = "default_allow_compression")] + pub allow_compression: bool, #[serde(default)] pub twilight_http_proxy: Option, pub externally_accessible_url: String, @@ -209,6 +211,10 @@ const fn default_validate_token() -> bool { true } +const fn default_allow_compression() -> bool { + true +} + pub enum Error { InvalidConfig(JsonError), NotFound(String), diff --git a/src/server.rs b/src/server.rs index d667905..ac2e256 100644 --- a/src/server.rs +++ b/src/server.rs @@ -271,11 +271,16 @@ pub async fn handle_client( trace!("[{addr}] Shard ID is {shard_id}"); - // Create a new session for this client - let session = Session { - shard_id, - compress: identify.d.compress, + let compress = { + if CONFIG.allow_compression { + identify.d.compress + } else { + Some(false) + } }; + + // Create a new session for this client + let session = Session { shard_id, compress }; let session_id = state.create_session(session); // The client is connected to this shard, so prepare for sending commands to it @@ -291,7 +296,7 @@ pub async fn handle_client( 0, ))); - let _res = sender.send(identify.d.compress); + let _res = sender.send(compress); } } 6 => { diff --git a/src/upgrade.rs b/src/upgrade.rs index 527be15..b69baa0 100644 --- a/src/upgrade.rs +++ b/src/upgrade.rs @@ -15,7 +15,7 @@ use tracing::error; use std::net::SocketAddr; -use crate::{server::handle_client, state::State}; +use crate::{config::CONFIG, server::handle_client, state::State}; /// Websocket GUID constant as specified in RFC6455: /// @@ -36,7 +36,8 @@ pub fn server( // Track whether the client requested zlib encoding in the query // string parameters - let use_zlib = query.map_or(false, |q| q.contains("compress=zlib-stream")); + let use_zlib = + CONFIG.allow_compression && query.map_or(false, |q| q.contains("compress=zlib-stream")); let mut response = Response::new(Full::default());