From 6d1db6801cf9063cfd0535e829b805570079d0a7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 12 Oct 2022 11:05:08 +0200 Subject: [PATCH] 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. :^) --- Ladybird/RequestManagerQt.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Ladybird/RequestManagerQt.cpp b/Ladybird/RequestManagerQt.cpp index 8529f4bb81..fa51c524ea 100644 --- a/Ladybird/RequestManagerQt.cpp +++ b/Ladybird/RequestManagerQt.cpp @@ -6,6 +6,7 @@ #include "RequestManagerQt.h" #include +#include 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>(); + for (auto const& cookie : set_cookie_list) { + set_cookie_headers.append(cookie.toRawForm().data()); + } } else { response_headers.set(name, value); }