Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub externally_accessible_url: String,
Expand Down Expand Up @@ -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),
Expand Down
15 changes: 10 additions & 5 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,16 @@ pub async fn handle_client<S: 'static + AsyncRead + AsyncWrite + Unpin + Send>(

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
Expand All @@ -291,7 +296,7 @@ pub async fn handle_client<S: 'static + AsyncRead + AsyncWrite + Unpin + Send>(
0,
)));

let _res = sender.send(identify.d.compress);
let _res = sender.send(compress);
}
}
6 => {
Expand Down
5 changes: 3 additions & 2 deletions src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
/// <https://datatracker.ietf.org/doc/html/rfc6455#section-1.3>
Expand All @@ -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());

Expand Down