summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@qt.io>2024-01-19 07:50:04 +0200
committerIvan Solovev <ivan.solovev@qt.io>2024-01-20 03:35:32 +0000
commitfd6dc2e9e7ce12d73e095a70b3259ea649f4a62d (patch)
tree2074aac410dc8bcf2c07c623832232753aabfe36 /src
parent196594003742f0bf1c075ed5b2ec93e06f237206 (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/network/access/qhttpheaders.cpp15
-rw-r--r--src/network/access/qhttpheaders.h2
-rw-r--r--src/network/access/qnetworkrequestfactory.cpp3
3 files changed, 2 insertions, 18 deletions
diff --git a/src/network/access/qhttpheaders.cpp b/src/network/access/qhttpheaders.cpp
index 1ea2890f219..7a640b509ca 100644
--- a/src/network/access/qhttpheaders.cpp
+++ b/src/network/access/qhttpheaders.cpp
@@ -889,21 +889,6 @@ bool QHttpHeaders::contains(WellKnownHeader name) const
}
/*!
- 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.
\sa removeAt(), removeAll(QHttpHeaders::WellKnownHeader)
diff --git a/src/network/access/qhttpheaders.h b/src/network/access/qhttpheaders.h
index a153d7911ef..1edbd03b12d 100644
--- a/src/network/access/qhttpheaders.h
+++ b/src/network/access/qhttpheaders.h
@@ -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);
diff --git a/src/network/access/qnetworkrequestfactory.cpp b/src/network/access/qnetworkrequestfactory.cpp
index 8a1ade8f78c..09413044046 100644
--- a/src/network/access/qnetworkrequestfactory.cpp
+++ b/src/network/access/qnetworkrequestfactory.cpp
@@ -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));