diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index 0272ff1899..79ef95eadf 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -1056,6 +1056,22 @@ static QByteArray headerName(QNetworkRequest::KnownHeaders header) return QByteArray(); } +static QByteArray makeCookieHeader(const QVariant &value, QNetworkCookie::RawForm type, QByteArrayView separator) +{ + QList cookies = qvariant_cast >(value); + if (cookies.isEmpty() && value.userType() == qMetaTypeId()) + cookies << qvariant_cast(value); + + QByteArray result; + for (const QNetworkCookie &cookie : std::as_const(cookies)) { + result += cookie.toRawForm(type); + result += separator; + } + if (!result.isEmpty()) + result.chop(separator.size()); + return result; +} + static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVariant &value) { switch (header) { @@ -1091,37 +1107,11 @@ static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVaria return value.toByteArray(); } - case QNetworkRequest::CookieHeader: { - QList cookies = qvariant_cast >(value); - if (cookies.isEmpty() && value.userType() == qMetaTypeId()) - cookies << qvariant_cast(value); + case QNetworkRequest::CookieHeader: + return makeCookieHeader(value, QNetworkCookie::NameAndValueOnly, "; "); - constexpr QByteArrayView separator = "; "; - QByteArray result; - for (const QNetworkCookie &cookie : std::as_const(cookies)) { - result += cookie.toRawForm(QNetworkCookie::NameAndValueOnly); - result += separator; - } - if (!result.isEmpty()) - result.chop(separator.size()); - return result; - } - - case QNetworkRequest::SetCookieHeader: { - QList cookies = qvariant_cast >(value); - if (cookies.isEmpty() && value.userType() == qMetaTypeId()) - cookies << qvariant_cast(value); -\ - constexpr QByteArrayView separator = ", "; - QByteArray result; - for (const QNetworkCookie &cookie : std::as_const(cookies)) { - result += cookie.toRawForm(QNetworkCookie::Full); - result += separator; - } - if (!result.isEmpty()) - result.chop(separator.size()); - return result; - } + case QNetworkRequest::SetCookieHeader: + return makeCookieHeader(value, QNetworkCookie::Full, ", "); } return QByteArray();