diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-12-14 15:31:38 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2024-01-09 18:54:46 +0100 |
commit | 7897ec88f426773cea38ce8c21091a05718a09e7 (patch) | |
tree | fd27302bed07663423e5a5f53fa17faab77fc98f /tests/auto/network | |
parent | 789cbeacdf1b894cde5e6cd6affc41d154716435 (diff) |
QHttpHeaders: add value(name, fall-back)
The vast majority of header fields appear only once, but there was no
efficient way to get that value: values() returns as a
QList<QByteArray> (allocating) while combinedValue() returns a
QByteArray constructed from values().join() (also allocating).
It follows that the QHttpHeaders API is incomplete (lacks an efficient
basis of operations in EoP terms).
Add a value() function that returns either the value or a
user-provided fall-back as a QByteArrayView. Unlike values() and
combinedValue(), this function can be noexcept, greatly improving
codegen for callers.
Found in API review.
Pick-to: 6.7
Task-number: QTBUG-107042
Change-Id: I2da20815fd46fdd7f150c224f41eee53abed313e
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/network')
-rw-r--r-- | tests/auto/network/access/qhttpheaders/tst_qhttpheaders.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/tests/auto/network/access/qhttpheaders/tst_qhttpheaders.cpp b/tests/auto/network/access/qhttpheaders/tst_qhttpheaders.cpp index 8e6c77e3dd..a88506fbfe 100644 --- a/tests/auto/network/access/qhttpheaders/tst_qhttpheaders.cpp +++ b/tests/auto/network/access/qhttpheaders/tst_qhttpheaders.cpp @@ -168,9 +168,10 @@ void tst_QHttpHeaders::accessors() QVERIFY(h1.has(QHttpHeaders::WellKnownHeader::Accept)); QVERIFY(h1.has("accept")); - // values() + // values()/value() #define EXISTS_NOT(H, N) do { \ QVERIFY(!H.has(N)); \ + QCOMPARE(H.value(N, "ENOENT"), "ENOENT"); \ const auto values = H.values(N); \ QVERIFY(values.isEmpty()); \ QVERIFY(H.combinedValue(N).isNull()); \ @@ -180,6 +181,7 @@ void tst_QHttpHeaders::accessors() const std::array expected = { __VA_ARGS__ }; \ static_assert(std::tuple_size_v<decltype(expected)> == X); \ QVERIFY(H.has(N)); \ + QCOMPARE(H.value(N, "ENOENT"), expected.front()); \ const auto values = H.values(N); \ QCOMPARE(values.size(), X); \ QCOMPARE(values.front(), expected.front()); \ |