Remove QHttpHeaders::names()
We need a way for users to consume the complete contents of
QHttpHeaders.
Until now, the only way was
for (const auto &name : h.names())
use(h.value/combinedValue(name));
which is quadratic.
Adding the usual iterators and operator[] would require us to
expose the underlying value_type, which we're not ready to do, yet.
So we added nameAt() and valueAt() functions in previous commits to
enable efficient indexed iteration without the need to expose a
value_type. Having added those, we can now remove names(), which had
the wrong value_type (QByteArrays are by definition UTF-8 in Qt, while
header names are L1), and is no longer needed to facilitate iteration.
In QNetworkRequestFactory, temporarily use toMultiMap() because we
need the combinedValue() of all headers here. The fix will be to make
QNetworkRequest QHttpHeaders-aware, but that's a Qt 6.8 thing, even
though we should still de-pessimize this code for Qt 6.7 with private
API.
Resulted from API-review.
Pick-to: 6.7
Change-Id: I65086ef4c62e22554ae7325a846bebc08b44916f
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
bb10
parent
1965940037
commit
fd6dc2e9e7
|
|
@ -888,21 +888,6 @@ bool QHttpHeaders::contains(WellKnownHeader name) const
|
|||
return contains(headerNames[qToUnderlying(name)]);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns a list of unique header names.
|
||||
Header names are case-insensitive, and the returned
|
||||
names are lower-cased.
|
||||
*/
|
||||
QList<QByteArray> QHttpHeaders::names() const
|
||||
{
|
||||
QList<QByteArray> names;
|
||||
for (const Header &header: d->headers) {
|
||||
if (!names.contains(header.name))
|
||||
names.append(header.name);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
/*!
|
||||
Removes the header \a name.
|
||||
|
||||
|
|
|
|||
|
|
@ -222,8 +222,6 @@ public:
|
|||
Q_NETWORK_EXPORT bool contains(QAnyStringView name) const;
|
||||
Q_NETWORK_EXPORT bool contains(WellKnownHeader name) const;
|
||||
|
||||
Q_NETWORK_EXPORT QList<QByteArray> names() const;
|
||||
|
||||
Q_NETWORK_EXPORT void clear();
|
||||
Q_NETWORK_EXPORT void removeAll(QAnyStringView name);
|
||||
Q_NETWORK_EXPORT void removeAll(WellKnownHeader name);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#endif
|
||||
|
||||
#include <QtCore/qloggingcategory.h>
|
||||
#include <QtCore/qmap.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -497,7 +498,7 @@ QNetworkRequest QNetworkRequestFactoryPrivate::newRequest(const QUrl &url) const
|
|||
// may be multiple values per name. Note: this would not necessarily
|
||||
// produce right result for 'Set-Cookie' header if it has multiple values,
|
||||
// but since it is a purely server-side (response) header, not relevant here.
|
||||
const auto headerNames = headers.names();
|
||||
const auto headerNames = headers.toMultiMap().uniqueKeys(); // ### fixme: port QNR to QHH
|
||||
for (const auto &name : headerNames)
|
||||
request.setRawHeader(name, headers.combinedValue(name));
|
||||
|
||||
|
|
|
|||
|
|
@ -166,26 +166,6 @@ void tst_QHttpHeaders::accessors()
|
|||
#undef EXISTS_N_TIMES
|
||||
#undef EXISTS_NOT
|
||||
|
||||
// names()
|
||||
h1.clear();
|
||||
QVERIFY(h1.names().isEmpty());
|
||||
h1.append(n1, v1);
|
||||
QCOMPARE(h1.names().size(), 1);
|
||||
QCOMPARE(h1.size(), 1);
|
||||
QVERIFY(h1.names().contains(n1));
|
||||
h1.append(n2, v2);
|
||||
QCOMPARE(h1.names().size(), 2);
|
||||
QCOMPARE(h1.size(), 2);
|
||||
QVERIFY(h1.names().contains(n1));
|
||||
QVERIFY(h1.names().contains(n2));
|
||||
h1.append(n1, v1);
|
||||
h1.append(n1, v1);
|
||||
QCOMPARE(h1.size(), 4);
|
||||
QCOMPARE(h1.names().size(), 2);
|
||||
h1.append(N1, v1); // uppercase of n1
|
||||
QCOMPARE(h1.size(), 5);
|
||||
QCOMPARE(h1.names().size(), 2);
|
||||
|
||||
// valueAt()
|
||||
h1.clear();
|
||||
h1.append(n1, v1);
|
||||
|
|
@ -353,7 +333,9 @@ void tst_QHttpHeaders::headerNameField()
|
|||
h1.append(u"abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&'*+-.^_`|~"_s,
|
||||
v1);
|
||||
QCOMPARE(h1.size(), 4);
|
||||
QCOMPARE(h1.names().size(), 1);
|
||||
QCOMPARE(h1.nameAt(0), h1.nameAt(1));
|
||||
QCOMPARE(h1.nameAt(1), h1.nameAt(2));
|
||||
QCOMPARE(h1.nameAt(2), h1.nameAt(3));
|
||||
h1.clear();
|
||||
|
||||
// Error cases
|
||||
|
|
|
|||
Loading…
Reference in New Issue