diff --git a/Libraries/LibWeb/WebSockets/WebSocket.cpp b/Libraries/LibWeb/WebSockets/WebSocket.cpp index 4cfb17ae6cf..f86e48adeb0 100644 --- a/Libraries/LibWeb/WebSockets/WebSocket.cpp +++ b/Libraries/LibWeb/WebSockets/WebSocket.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -130,7 +131,23 @@ ErrorOr WebSocket::establish_web_socket_connection(URL::URL& url_record, V for (auto const& protocol : protocols) TRY(protcol_byte_strings.try_append(protocol.to_byte_string())); - m_websocket = ResourceLoader::the().request_client().websocket_connect(url_record, origin_string, protcol_byte_strings); + HTTP::HeaderMap additional_headers; + + auto cookies = ([&] { + // FIXME: Getting to the page client reliably is way too complicated, and going via the document won't work in workers. + auto document = client.responsible_document(); + if (!document) + return String {}; + + // NOTE: The WebSocket handshake is sent as an HTTP request, so the source should be Http. + return document->page().client().page_did_request_cookie(url_record, Cookie::Source::Http); + })(); + + if (!cookies.is_empty()) { + additional_headers.set("Cookie", cookies.to_byte_string()); + } + + m_websocket = ResourceLoader::the().request_client().websocket_connect(url_record, origin_string, protcol_byte_strings, {}, additional_headers); m_websocket->on_open = [weak_this = make_weak_ptr()] { if (!weak_this)