fix: restore working websocket message size configuration options

This commit is contained in:
Greg Heartsfield 2022-01-05 17:41:12 -05:00
parent 7037555516
commit da7968efef

View File

@ -32,12 +32,15 @@ use tokio_tungstenite::WebSocketStream;
use tungstenite::handshake; use tungstenite::handshake;
use tungstenite::protocol::WebSocketConfig; use tungstenite::protocol::WebSocketConfig;
/// Return a requested DB name from command line arguments.
fn db_from_args(args: Vec<String>) -> Option<String> { fn db_from_args(args: Vec<String>) -> Option<String> {
if args.len() == 3 && args.get(1) == Some(&"--db".to_owned()) { if args.len() == 3 && args.get(1) == Some(&"--db".to_owned()) {
return args.get(2).map(|x| x.to_owned()); return args.get(2).map(|x| x.to_owned());
} }
None None
} }
/// Handle arbitrary HTTP requests, including for WebSocket upgrades.
async fn handle_web_request( async fn handle_web_request(
mut request: Request<Body>, mut request: Request<Body>,
remote_addr: SocketAddr, remote_addr: SocketAddr,
@ -64,13 +67,20 @@ async fn handle_web_request(
match upgrade::on(&mut request).await { match upgrade::on(&mut request).await {
//if successfully upgraded //if successfully upgraded
Ok(upgraded) => { Ok(upgraded) => {
// set WebSocket configuration options
let mut config = WebSocketConfig::default();
{
let settings = config::SETTINGS.read().unwrap();
config.max_message_size = settings.limits.max_ws_message_bytes;
config.max_frame_size = settings.limits.max_ws_frame_bytes;
}
//create a websocket stream from the upgraded object //create a websocket stream from the upgraded object
let ws_stream = WebSocketStream::from_raw_socket( let ws_stream = WebSocketStream::from_raw_socket(
//pass the upgraded object //pass the upgraded object
//as the base layer stream of the Websocket //as the base layer stream of the Websocket
upgraded, upgraded,
tokio_tungstenite::tungstenite::protocol::Role::Server, tokio_tungstenite::tungstenite::protocol::Role::Server,
None, Some(config),
) )
.await; .await;
tokio::spawn(nostr_server( tokio::spawn(nostr_server(
@ -243,12 +253,6 @@ async fn nostr_server(
) { ) {
// get a broadcast channel for clients to communicate on // get a broadcast channel for clients to communicate on
let mut bcast_rx = broadcast.subscribe(); let mut bcast_rx = broadcast.subscribe();
let mut config = WebSocketConfig::default();
{
let settings = config::SETTINGS.read().unwrap();
config.max_message_size = settings.limits.max_ws_message_bytes;
config.max_frame_size = settings.limits.max_ws_frame_bytes;
}
// upgrade the TCP connection to WebSocket // upgrade the TCP connection to WebSocket
//let conn = tokio_tungstenite::accept_async_with_config(stream, Some(config)).await; //let conn = tokio_tungstenite::accept_async_with_config(stream, Some(config)).await;
//let ws_stream = conn.expect("websocket handshake error"); //let ws_stream = conn.expect("websocket handshake error");