Add space character when combining QHttpHeaders values with comma

The "HTTP RFC 9110 5.3 Field Order" states that the values combined
with comma can be followed up by an optional whitespace, and for
consistency recommends "comma SP". This is also what eg. 'MDN Web
Headers' class does.

Fixes: QTBUG-122650
Pick-to: 6.7
Change-Id: I3391c86018090f0b8721929b64a7e3029e98ac85
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
bb10
Juha Vuolle 2024-02-22 17:08:13 +02:00
parent 9af3a6c146
commit 1fbcb411e1
3 changed files with 10 additions and 10 deletions

View File

@ -51,15 +51,15 @@ Q_LOGGING_CATEGORY(lcQHttpHeaders, "qt.network.http.headers");
\section1 Combining values
Most HTTP header values can be combined with a single comma \c {','},
and the semantic meaning is preserved. As an example, these two should be
semantically similar:
Most HTTP header values can be combined with a single comma \c {','}
plus an optional whitespace, and the semantic meaning is preserved.
As an example, these two should be semantically similar:
\badcode
// Values as separate header entries
myheadername: myheadervalue1
myheadername: myheadervalue2
// Combined value
myheadername: myheadervalue1,myheadervalue2
myheadername: myheadervalue1, myheadervalue2
\endcode
However there is a notable exception to this rule:
@ -1023,7 +1023,7 @@ QByteArray QHttpHeaders::combinedValue(QAnyStringView name) const
for (const auto &v : valueList) {
result.append(separator);
result.append(v);
separator = ",";
separator = ", ";
}
return result;
}

View File

@ -81,7 +81,7 @@ void tst_QHttpHeaders::constructors()
QHttpHeaders hmap = QHttpHeaders::fromMultiMap(map);
QHttpHeaders hhash = QHttpHeaders::fromMultiHash(hash);
CONTAINS_HEADER(nb1, v1);
CONTAINS_HEADER(nb2, nv2 + "," + nv2)
CONTAINS_HEADER(nb2, nv2 + ", " + nv2)
#undef CONTAINS_HEADER
}
@ -129,7 +129,7 @@ void tst_QHttpHeaders::accessors()
QCOMPARE(values.front(), expected.front()); \
/* ignore in-between */ \
QCOMPARE(values.back(), expected.back()); \
QCOMPARE(H.combinedValue(N), values.join(',')); \
QCOMPARE(H.combinedValue(N), values.join(", ")); \
} while (false)
#define EXISTS_ONCE(H, N, V) EXISTS_N_TIMES(1, H, N, V)
@ -428,7 +428,7 @@ void tst_QHttpHeaders::headerValueField()
h1.append(n1, " foo ");
QCOMPARE(h1.combinedValue(n1), "foo");
h1.append(n1, "\tbar\t");
QCOMPARE(h1.combinedValue(n1), "foo,bar");
QCOMPARE(h1.combinedValue(n1), "foo, bar");
QCOMPARE(h1.size(), 2);
h1.clear();

View File

@ -237,10 +237,10 @@ void tst_QNetworkRequestFactory::headers()
h1.append(name1, value3);
factory.setCommonHeaders(h1);
QVERIFY(factory.commonHeaders().contains(name1));
QCOMPARE(factory.commonHeaders().combinedValue(name1), value1 + ',' + value2 + ',' + value3);
QCOMPARE(factory.commonHeaders().combinedValue(name1), value1 + ", " + value2 + ", " + value3);
request = factory.createRequest();
QVERIFY(request.hasRawHeader(name1));
QCOMPARE(request.rawHeader(name1), value1 + ',' + value2 + ',' + value3);
QCOMPARE(request.rawHeader(name1), value1 + ", " + value2 + ", " + value3);
}
void tst_QNetworkRequestFactory::bearerToken()