Skip to content

Commit 124b4bb

Browse files
enscctron
authored andcommitted
fix: websocket: respond to Ping messages
RFC6455 requires in section "5.5.2 Ping" | Upon receipt of a Ping frame, an endpoint MUST send a Pong frame in | response Not doing this causes e.g. Firefox to close the websocket automatically which triggers an (unwanted) reload of the page. Signed-off-by: Enrico Scholz <[email protected]>
1 parent b9eac59 commit 124b4bb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/ws.rs

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ pub(crate) async fn handle_ws(mut ws: WebSocket, state: Arc<serve::State>) {
3838
let _ = ws.close().await;
3939
return
4040
}
41+
Some(Ok(Message::Ping(msg))) => {
42+
tracing::trace!("responding to Ping");
43+
let _ = ws.send(Message::Pong(msg)).await;
44+
}
4145
Some(Ok(msg)) => {
4246
tracing::debug!("received message from browser: {msg:?} (ignoring)");
4347
}

0 commit comments

Comments
 (0)