Ladybird/RequestManagerQt: Unwrap multiple cookies masquerading as one

Qt can wrap any number of cookies into a single Set-Cookie header in the
network responses it gives us. We now use the QNetworkReply::header()
API to get a "cooked" list of the cookies, and then rewrap them in a
format suitable for LibWeb.

Sites that send multiple Set-Cookie headers in one response now work
a lot better. :^)
This commit is contained in:
Andreas Kling 2022-10-12 11:05:08 +02:00 committed by Andrew Kaster
parent 195cdb33de
commit 6d1db6801c
Notes: sideshowbarker 2024-07-17 02:57:43 +09:00

View file

@ -6,6 +6,7 @@
#include "RequestManagerQt.h"
#include <AK/JsonObject.h>
#include <QNetworkCookie>
RequestManagerQt::RequestManagerQt()
{
@ -81,7 +82,12 @@ void RequestManagerQt::Request::did_finish()
auto name = String(it.first.data(), it.first.length());
auto value = String(it.second.data(), it.second.length());
if (name.equals_ignoring_case("set-cookie"sv)) {
set_cookie_headers.append(value);
// NOTE: Qt may have bundled multiple Set-Cookie headers into a single one.
// We have to extract the full list of cookies via QNetworkReply::header().
auto set_cookie_list = m_reply.header(QNetworkRequest::SetCookieHeader).value<QList<QNetworkCookie>>();
for (auto const& cookie : set_cookie_list) {
set_cookie_headers.append(cookie.toRawForm().data());
}
} else {
response_headers.set(name, value);
}