-
I would like to be able to configure things like the max message size when using Poem's WebSocket. This is available on the underlying tungstenite WebSocketStream that Poem wraps, but I do not see it exposed through Poem. The end result is something like the following, which seems … less than ideal: #[handler]
pub async fn handler(ws: WebSocket) -> impl IntoResponse {
ws.on_upgrade(|mut socket| async move {
unsafe {
let poem_stream: *const poem::web::websocket::WebSocketStream = &socket;
let tung_stream = poem_stream as *const tokio_tungstenite::WebSocketStream<poem::Upgraded>;
let config_const: *const tungstenite::protocol::WebSocketConfig = (*tung_stream).get_config();
let config = config_const as *mut tungstenite::protocol::WebSocketConfig;
(*config).max_message_size = Some(32 << 20);
(*config).max_frame_size = Some(8 << 20);
}
... The pointers do not bother me (hey, I grew up on C), but two other things do:
Have I overlooked some "blessed" way to configure the WebSocketStream? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Added |
Beta Was this translation helpful? Give feedback.
-
Cool! So we would call |
Beta Was this translation helpful? Give feedback.
-
@sunli829 — Thank you again for your quick attention to this request. Now that I am using this I have come across another desire; that is, the ability to get the current configuration. For reference, the tungstenite library has a Thank you! |
Beta Was this translation helpful? Give feedback.
Cool! So we would call
WebSocket::config()
in the handler right beforeWebSocket::on_upgrade()
?