Skip to content

Commit

Permalink
fix: websocket: respond to Ping messages
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ensc authored and ctron committed Jan 20, 2025
1 parent c5ead2c commit 889a4e3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ pub(crate) async fn handle_ws(mut ws: WebSocket, state: Arc<serve::State>) {
let _ = ws.close().await;
return
}
Some(Ok(Message::Ping(msg))) => {
tracing::trace!("responding to Ping");
let _ = ws.send(Message::Pong(msg)).await;
}
Some(Ok(msg)) => {
tracing::debug!("received message from browser: {msg:?} (ignoring)");
}
Expand Down

0 comments on commit 889a4e3

Please sign in to comment.