diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index a7a5ca5e39..0272ff1899 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -1096,14 +1096,14 @@ static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVaria if (cookies.isEmpty() && value.userType() == qMetaTypeId()) cookies << qvariant_cast(value); + constexpr QByteArrayView separator = "; "; QByteArray result; - bool first = true; for (const QNetworkCookie &cookie : std::as_const(cookies)) { - if (!first) - result += "; "; - first = false; result += cookie.toRawForm(QNetworkCookie::NameAndValueOnly); + result += separator; } + if (!result.isEmpty()) + result.chop(separator.size()); return result; } @@ -1111,15 +1111,15 @@ static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVaria QList cookies = qvariant_cast >(value); if (cookies.isEmpty() && value.userType() == qMetaTypeId()) cookies << qvariant_cast(value); - +\ + constexpr QByteArrayView separator = ", "; QByteArray result; - bool first = true; for (const QNetworkCookie &cookie : std::as_const(cookies)) { - if (!first) - result += ", "; - first = false; result += cookie.toRawForm(QNetworkCookie::Full); + result += separator; } + if (!result.isEmpty()) + result.chop(separator.size()); return result; } }