From 18b5debc3f4214d103e0de457b541b1b72dc8131 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Thu, 4 Aug 2022 18:29:04 +0200 Subject: [PATCH] fix: increase websocket message size (#15406) --- ext/websocket/lib.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs index 267231238b..0e642be3f9 100644 --- a/ext/websocket/lib.rs +++ b/ext/websocket/lib.rs @@ -40,12 +40,13 @@ use tokio::net::TcpStream; use tokio_rustls::rustls::RootCertStore; use tokio_rustls::rustls::ServerName; use tokio_rustls::TlsConnector; -use tokio_tungstenite::client_async; +use tokio_tungstenite::client_async_with_config; use tokio_tungstenite::tungstenite::handshake::client::Response; use tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode; use tokio_tungstenite::tungstenite::protocol::CloseFrame; use tokio_tungstenite::tungstenite::protocol::Message; use tokio_tungstenite::tungstenite::protocol::Role; +use tokio_tungstenite::tungstenite::protocol::WebSocketConfig; use tokio_tungstenite::MaybeTlsStream; use tokio_tungstenite::WebSocketStream; @@ -84,8 +85,16 @@ pub async fn ws_create_server_stream( state: &Rc>, transport: hyper::upgrade::Upgraded, ) -> Result { - let ws_stream = - WebSocketStream::from_raw_socket(transport, Role::Server, None).await; + let ws_stream = WebSocketStream::from_raw_socket( + transport, + Role::Server, + Some(WebSocketConfig { + max_message_size: Some(128 << 20), + max_frame_size: Some(32 << 20), + ..Default::default() + }), + ) + .await; let (ws_tx, ws_rx) = ws_stream.split(); let ws_resource = WsStreamResource { @@ -322,7 +331,15 @@ where _ => unreachable!(), }; - let client = client_async(request, socket); + let client = client_async_with_config( + request, + socket, + Some(WebSocketConfig { + max_message_size: Some(128 << 20), + max_frame_size: Some(32 << 20), + ..Default::default() + }), + ); let (stream, response): (WsStream, Response) = if let Some(cancel_resource) = cancel_resource { client.or_cancel(cancel_resource.0.to_owned()).await?