From c39d84fdc2cc5dc34745eea868d0ce12a16d9141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3rebe=20-=20Romain=20GERARD?= Date: Tue, 8 Oct 2024 23:08:38 +0200 Subject: [PATCH] fix(#365): correctly downcast websocket cnx when not using tls --- src/tunnel/server/handler_websocket.rs | 8 +++++++- src/tunnel/transport/websocket.rs | 3 +-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tunnel/server/handler_websocket.rs b/src/tunnel/server/handler_websocket.rs index 5599c9b..44e6df8 100644 --- a/src/tunnel/server/handler_websocket.rs +++ b/src/tunnel/server/handler_websocket.rs @@ -47,7 +47,13 @@ pub(super) async fn ws_server_upgrade( tokio::spawn( async move { let (ws_rx, ws_tx) = match fut.await { - Ok(ws) => mk_websocket_tunnel(ws, Role::Server, mask_frame)?, + Ok(ws) => match mk_websocket_tunnel(ws, Role::Server, mask_frame) { + Ok(ws) => ws, + Err(err) => { + error!("Error during http upgrade request: {:?}", err); + return Err(err); + } + }, Err(err) => { error!("Error during http upgrade request: {:?}", err); return Err(anyhow::Error::from(err)); diff --git a/src/tunnel/transport/websocket.rs b/src/tunnel/transport/websocket.rs index 95e2623..3f53453 100644 --- a/src/tunnel/transport/websocket.rs +++ b/src/tunnel/transport/websocket.rs @@ -319,8 +319,7 @@ pub fn mk_websocket_tunnel( WebSocket::after_handshake(transport, role) } Err(upgraded) => { - let stream = upgraded - .downcast::>() + let stream = hyper_util::server::conn::auto::upgrade::downcast::>(upgraded) .map_err(|_| anyhow!("cannot downcast websocket server stream"))?; let transport = TransportStream::from_tcp(stream.io.into_inner(), stream.read_buf); WebSocket::after_handshake(transport, role)