1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

Everywhere: Merge the WebSocket service into RequestServer

This keeps the APIs separate as they are wildly different, a future
improvement could be to somehow unify the APIs (if possible).

Closes #23080.
This commit is contained in:
Ali Mohammad Pur 2024-03-06 01:50:52 +01:00 committed by Jelle Raaijmakers
parent daf5484d6b
commit 6dfb2f9dc8
56 changed files with 231 additions and 845 deletions

View file

@ -103,6 +103,54 @@ void RequestClient::certificate_requested(i32 request_id)
}
}
RefPtr<WebSocket> RequestClient::websocket_connect(const URL& url, ByteString const& origin, Vector<ByteString> const& protocols, Vector<ByteString> const& extensions, HashMap<ByteString, ByteString> const& request_headers)
{
auto headers_or_error = request_headers.clone();
if (headers_or_error.is_error())
return nullptr;
auto connection_id = IPCProxy::websocket_connect(url, origin, protocols, extensions, headers_or_error.release_value());
if (connection_id < 0)
return nullptr;
auto connection = WebSocket::create_from_id({}, *this, connection_id);
m_websockets.set(connection_id, connection);
return connection;
}
void RequestClient::websocket_connected(i32 connection_id)
{
auto maybe_connection = m_websockets.get(connection_id);
if (maybe_connection.has_value())
maybe_connection.value()->did_open({});
}
void RequestClient::websocket_received(i32 connection_id, bool is_text, ByteBuffer const& data)
{
auto maybe_connection = m_websockets.get(connection_id);
if (maybe_connection.has_value())
maybe_connection.value()->did_receive({}, data, is_text);
}
void RequestClient::websocket_errored(i32 connection_id, i32 message)
{
auto maybe_connection = m_websockets.get(connection_id);
if (maybe_connection.has_value())
maybe_connection.value()->did_error({}, message);
}
void RequestClient::websocket_closed(i32 connection_id, u16 code, ByteString const& reason, bool clean)
{
auto maybe_connection = m_websockets.get(connection_id);
if (maybe_connection.has_value())
maybe_connection.value()->did_close({}, code, reason, clean);
}
void RequestClient::websocket_certificate_requested(i32 connection_id)
{
auto maybe_connection = m_websockets.get(connection_id);
if (maybe_connection.has_value())
maybe_connection.value()->did_request_certificates({});
}
}
template RefPtr<Protocol::Request> Protocol::RequestClient::start_request(ByteString const& method, URL const&, HashMap<ByteString, ByteString> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const&);