Skip to content
This repository was archived by the owner on Dec 25, 2022. It is now read-only.

Commit addabea

Browse files
committed
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. :^)
1 parent 81d390c commit addabea

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

RequestManagerQt.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "RequestManagerQt.h"
88
#include <AK/JsonObject.h>
9+
#include <QNetworkCookie>
910

1011
RequestManagerQt::RequestManagerQt()
1112
{
@@ -81,7 +82,12 @@ void RequestManagerQt::Request::did_finish()
8182
auto name = String(it.first.data(), it.first.length());
8283
auto value = String(it.second.data(), it.second.length());
8384
if (name.equals_ignoring_case("set-cookie"sv)) {
84-
set_cookie_headers.append(value);
85+
// NOTE: Qt may have bundled multiple Set-Cookie headers into a single one.
86+
// We have to extract the full list of cookies via QNetworkReply::header().
87+
auto set_cookie_list = m_reply.header(QNetworkRequest::SetCookieHeader).value<QList<QNetworkCookie>>();
88+
for (auto const& cookie : set_cookie_list) {
89+
set_cookie_headers.append(cookie.toRawForm().data());
90+
}
8591
} else {
8692
response_headers.set(name, value);
8793
}

0 commit comments

Comments
 (0)