Commit Graph

12 Commits (f45dffa8b4e5a3ddc3473203e27ebdeebfde10da)

Author SHA1 Message Date
Lucie Gérard ff1039c217 Change license for tests files
According to QUIP-18 [1], all tests file should be
LicenseRef-Qt-Commercial OR GPL-3.0-only

[1]: https://contribute.qt-project.org/quips/18

Pick-to: 6.7
Task-number: QTBUG-121787
Change-Id: I9657df5d660820e56c96d511ea49d321c54682e8
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
2024-02-04 09:56:42 +01:00
Juha Vuolle fd6dc2e9e7 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>
2024-01-20 03:35:32 +00:00
Juha Vuolle 1965940037 Add QHttpHeaders::nameAt() 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 nameAt() and (in a previous commit) valueAt() functions to
enable efficient indexed iteration without the need to expose a
value_type.

Return by QLatin1StringView, not QAnyStringView, because that
statically encodes the actual encoding used (and required by HTTP
specs and promised by the class documentation, so it won't need to
change). For the setters, we want to be accomodating QString,
QByteArray, etc, which is why those take QAnyStringView.

Resulted from API-review.

Pick-to: 6.7
Change-Id: I0153c5aad0f6260b5dbc963de0aaf4ef42fdd4f1
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2024-01-20 04:35:29 +01:00
Juha Vuolle 4bb12dab6a 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>
2024-01-20 03:35:25 +00:00
Axel Spoerl 84b792fa98 Add missing include in tst_QHttpHeaders
A QMultiMap is used, while only qset.h is included.
FTBFS w/o precompiled headers.

Include qmap.h as well.

Pick-to: 6.7 6.6 6.5
Change-Id: I5f6e1d204bfa94cc6a81f6883c7a7b0ee1e9963c
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2024-01-18 21:17:17 +01:00
Juha Vuolle 37549cda72 Add static access function to wellknown headers
Resulted from API-review

Pick-to: 6.7
Change-Id: I438a5cf9c88b572adece99af0314eefbc4371f8f
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-01-17 05:46:36 +02:00
Juha Vuolle 89dab8578c Remove HTTP headers equals() / comparison
There's several ways to compare HTTP headers, and arguably
the need for it is not very high. For the time being users can use
different accessors and compare in ways that make sense for
their use cases.

Consequently since HTTP headers are no longer trivially comparable,
it makes also comparing the request factories more 'moot' because
headers are a central piece of request information. So removed
comparison from request factory as well.

These comparisons can be restored later if a clear understanding
on it's need, and on how it should be best done, emerges.

Resulted from API-review

Pick-to: 6.7
Change-Id: Idb5ab3710268b52a8e59656db8cc7de82f0ae511
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2024-01-15 10:29:07 +02:00
Juha Vuolle e2462b09b7 Rename QHttpHeaders::has() to contains()
Resulted from API-review

Pick-to: 6.7
Change-Id: I84e880dc6edb9c62fd1ddd50d477347443fd52a7
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2024-01-11 14:22:08 +02:00
Marc Mutz 7897ec88f4 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>
2024-01-09 18:54:46 +01:00
Marc Mutz 789cbeacdf tst_QHttpHeaders: DRY the value() test
Clean up the C'n'P in the test a bit before adding tests of new
functions.

Pick-to: 6.7
Task-number: QTBUG-107042
Change-Id: I2da20815fd46fdd7f150c224f41eee53abed313d
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-01-09 18:54:46 +01:00
Marc Mutz 2c65f2cd11 tst_QHttpHeaders: don't convert QAnyStringView
QList::contains() supports heterogeneous lookups, so just pass the QAnyStringView.

Pick-to: 6.7
Task-number: QTBUG-107042
Change-Id: I442c2a6271953859dc47f9c3bd5cbc0074f55a9f
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-01-09 18:54:46 +01:00
Juha Vuolle 925ce9e908 Add QHttpHeaders class
New QHttpHeaders class for use in place of
std::pair<QBA,QBA>, QMap<QBA>, and QMultiMap/Hash<QBA,QBA>
to represent HTTP headers.

[ChangeLog][QtNetwork][QHttpHeaders] New QHttpHeaders class

Task-number: QTBUG-107042
Change-Id: I54766886a491acfc9a813a3414322a75011acb9d
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-12-08 15:53:32 +02:00