fix(#365): correctly downcast websocket cnx when not using tls

This commit is contained in:
Σrebe - Romain GERARD 2024-10-08 23:08:38 +02:00
parent 57a142c9ca
commit c39d84fdc2
2 changed files with 8 additions and 3 deletions

View file

@ -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));

View file

@ -319,8 +319,7 @@ pub fn mk_websocket_tunnel(
WebSocket::after_handshake(transport, role)
}
Err(upgraded) => {
let stream = upgraded
.downcast::<TokioIo<TcpStream>>()
let stream = hyper_util::server::conn::auto::upgrade::downcast::<TokioIo<TcpStream>>(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)