Add QHttpHeaders::valueAt() function
We need a way for users to consume the complete contents of
QHttpHeaders.
For now, the only way is
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 add valueAt() and (in a follow-up) nameAt() functions to enable
efficient indexed iteration without the need to expose a value_type.
Resulted from API-review
Pick-to: 6.7
Change-Id: I863f59618cea5682386ce26b66b4b1655eac7950
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
bb10
parent
a5292ad2f5
commit
4bb12dab6a
|
|
@ -987,6 +987,18 @@ QList<QByteArray> QHttpHeaders::values(WellKnownHeader name) const
|
|||
return values(headerNames[qToUnderlying(name)]);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the header value at index \a i. The index \a i must be valid
|
||||
(see \l size()).
|
||||
|
||||
\sa size(), value(), values(), combinedValue()
|
||||
*/
|
||||
QByteArrayView QHttpHeaders::valueAt(qsizetype i) const noexcept
|
||||
{
|
||||
d->verify(i);
|
||||
return d->headers.at(i).value;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the values of header \a name in a comma-combined string.
|
||||
Returns a \c null QByteArray if the header with \a name doesn't
|
||||
|
|
|
|||
|
|
@ -235,6 +235,8 @@ public:
|
|||
Q_NETWORK_EXPORT QList<QByteArray> values(QAnyStringView name) const;
|
||||
Q_NETWORK_EXPORT QList<QByteArray> values(WellKnownHeader name) const;
|
||||
|
||||
Q_NETWORK_EXPORT QByteArrayView valueAt(qsizetype i) const noexcept;
|
||||
|
||||
Q_NETWORK_EXPORT QByteArray combinedValue(QAnyStringView name) const;
|
||||
Q_NETWORK_EXPORT QByteArray combinedValue(WellKnownHeader name) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -186,6 +186,15 @@ void tst_QHttpHeaders::accessors()
|
|||
QCOMPARE(h1.size(), 5);
|
||||
QCOMPARE(h1.names().size(), 2);
|
||||
|
||||
// valueAt()
|
||||
h1.clear();
|
||||
h1.append(n1, v1);
|
||||
h1.append(n2, v2);
|
||||
h1.append(n3, v3);
|
||||
QCOMPARE(h1.valueAt(0), v1);
|
||||
QCOMPARE(h1.valueAt(1), v2);
|
||||
QCOMPARE(h1.valueAt(2), v3);
|
||||
|
||||
// removeAll()
|
||||
h1.clear();
|
||||
QVERIFY(h1.append(n1, v1));
|
||||
|
|
|
|||
Loading…
Reference in New Issue