mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-26 12:17:52 +00:00
LibWeb: Make WebSocket closure adhere to spec for all ReadyStates
This commit is contained in:
parent
5ec70bd00a
commit
6077c51468
Notes:
github-actions[bot]
2025-08-18 15:36:57 +00:00
Author: https://github.com/hopafoot
Commit: 6077c51468
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5731
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/gmta
1 changed files with 13 additions and 0 deletions
|
@ -97,17 +97,27 @@ void WebSocket::send(Message const& message)
|
|||
|
||||
void WebSocket::close(u16 code, ByteString const& message)
|
||||
{
|
||||
// Section 3.1: close(code, reason): https://websockets.spec.whatwg.org/#the-websocket-interface
|
||||
VERIFY(m_impl);
|
||||
|
||||
switch (m_state) {
|
||||
case InternalState::Closed:
|
||||
case InternalState::Closing:
|
||||
// "If this’s ready state is CLOSING (2) or CLOSED (3)
|
||||
// Do nothing."
|
||||
break;
|
||||
case InternalState::NotStarted:
|
||||
case InternalState::EstablishingProtocolConnection:
|
||||
case InternalState::SendingClientHandshake:
|
||||
case InternalState::WaitingForServerHandshake:
|
||||
// "If the WebSocket connection is not yet established [WSP]
|
||||
// Fail the WebSocket connection and set this’s ready state to CLOSING (2)."
|
||||
// FIXME: Fail the connection.
|
||||
set_state(InternalState::Closing);
|
||||
break;
|
||||
case InternalState::Open: {
|
||||
// "If the WebSocket closing handshake has not yet been started [WSP]
|
||||
// Start the WebSocket closing handshake and set this’s ready state to CLOSING (2)."
|
||||
auto message_bytes = message.bytes();
|
||||
auto close_payload = ByteBuffer::create_uninitialized(message_bytes.size() + 2).release_value_but_fixme_should_propagate_errors(); // FIXME: Handle possible OOM situation.
|
||||
close_payload.overwrite(0, (u8*)&code, 2);
|
||||
|
@ -117,6 +127,9 @@ void WebSocket::close(u16 code, ByteString const& message)
|
|||
break;
|
||||
}
|
||||
default:
|
||||
// "Otherwise
|
||||
// Set this’s ready state to CLOSING (2)."
|
||||
set_state(InternalState::Closing);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue