qnetworkrequest, qnetworkreply: port some methods to QBAV
[ChangeLog][QtNetwork] Ported hasRawHeader and rawHeader of QNetworkReply and QNetworkRequest to QByteArrayView. Change-Id: Ife71ba11b1ee8907c104dba3210d7a033568edf4 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
be7e5f94a1
commit
56bb4ac484
@ -26,6 +26,7 @@ qt_internal_add_module(Network
|
|||||||
access/qnetworkreplyfileimpl.cpp access/qnetworkreplyfileimpl_p.h
|
access/qnetworkreplyfileimpl.cpp access/qnetworkreplyfileimpl_p.h
|
||||||
access/qnetworkreplyimpl.cpp access/qnetworkreplyimpl_p.h
|
access/qnetworkreplyimpl.cpp access/qnetworkreplyimpl_p.h
|
||||||
access/qnetworkrequest.cpp access/qnetworkrequest.h access/qnetworkrequest_p.h
|
access/qnetworkrequest.cpp access/qnetworkrequest.h access/qnetworkrequest_p.h
|
||||||
|
compat/removed_api.cpp
|
||||||
kernel/qauthenticator.cpp kernel/qauthenticator.h kernel/qauthenticator_p.h
|
kernel/qauthenticator.cpp kernel/qauthenticator.h kernel/qauthenticator_p.h
|
||||||
kernel/qhostaddress.cpp kernel/qhostaddress.h kernel/qhostaddress_p.h
|
kernel/qhostaddress.cpp kernel/qhostaddress.h kernel/qhostaddress_p.h
|
||||||
kernel/qhostinfo.cpp kernel/qhostinfo.h kernel/qhostinfo_p.h
|
kernel/qhostinfo.cpp kernel/qhostinfo.h kernel/qhostinfo_p.h
|
||||||
@ -64,6 +65,8 @@ qt_internal_add_module(Network
|
|||||||
Qt::Core
|
Qt::Core
|
||||||
PRIVATE_MODULE_INTERFACE
|
PRIVATE_MODULE_INTERFACE
|
||||||
Qt::CorePrivate
|
Qt::CorePrivate
|
||||||
|
NO_PCH_SOURCES
|
||||||
|
compat/removed_api.cpp
|
||||||
PRECOMPILED_HEADER
|
PRECOMPILED_HEADER
|
||||||
"../corelib/global/qt_pch.h"
|
"../corelib/global/qt_pch.h"
|
||||||
GENERATE_CPP_EXPORTS
|
GENERATE_CPP_EXPORTS
|
||||||
|
@ -612,8 +612,9 @@ QVariant QNetworkReply::header(QNetworkRequest::KnownHeaders header) const
|
|||||||
the remote server
|
the remote server
|
||||||
|
|
||||||
\sa rawHeader()
|
\sa rawHeader()
|
||||||
|
\note In Qt versions prior to 6.7, this function took QByteArray only.
|
||||||
*/
|
*/
|
||||||
bool QNetworkReply::hasRawHeader(const QByteArray &headerName) const
|
bool QNetworkReply::hasRawHeader(QByteArrayView headerName) const
|
||||||
{
|
{
|
||||||
Q_D(const QNetworkReply);
|
Q_D(const QNetworkReply);
|
||||||
return d->findRawHeader(headerName) != d->rawHeaders.constEnd();
|
return d->findRawHeader(headerName) != d->rawHeaders.constEnd();
|
||||||
@ -627,13 +628,12 @@ bool QNetworkReply::hasRawHeader(const QByteArray &headerName) const
|
|||||||
header field.
|
header field.
|
||||||
|
|
||||||
\sa setRawHeader(), hasRawHeader(), header()
|
\sa setRawHeader(), hasRawHeader(), header()
|
||||||
|
\note In Qt versions prior to 6.7, this function took QByteArray only.
|
||||||
*/
|
*/
|
||||||
QByteArray QNetworkReply::rawHeader(const QByteArray &headerName) const
|
QByteArray QNetworkReply::rawHeader(QByteArrayView headerName) const
|
||||||
{
|
{
|
||||||
Q_D(const QNetworkReply);
|
Q_D(const QNetworkReply);
|
||||||
QNetworkHeadersPrivate::RawHeadersList::ConstIterator it =
|
if (const auto it = d->findRawHeader(headerName); it != d->rawHeaders.constEnd())
|
||||||
d->findRawHeader(headerName);
|
|
||||||
if (it != d->rawHeaders.constEnd())
|
|
||||||
return it->second;
|
return it->second;
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
@ -97,9 +97,15 @@ public:
|
|||||||
QVariant header(QNetworkRequest::KnownHeaders header) const;
|
QVariant header(QNetworkRequest::KnownHeaders header) const;
|
||||||
|
|
||||||
// raw headers:
|
// raw headers:
|
||||||
|
#if QT_NETWORK_REMOVED_SINCE(6, 7)
|
||||||
bool hasRawHeader(const QByteArray &headerName) const;
|
bool hasRawHeader(const QByteArray &headerName) const;
|
||||||
|
#endif
|
||||||
|
bool hasRawHeader(QByteArrayView headerName) const;
|
||||||
QList<QByteArray> rawHeaderList() const;
|
QList<QByteArray> rawHeaderList() const;
|
||||||
|
#if QT_NETWORK_REMOVED_SINCE(6, 7)
|
||||||
QByteArray rawHeader(const QByteArray &headerName) const;
|
QByteArray rawHeader(const QByteArray &headerName) const;
|
||||||
|
#endif
|
||||||
|
QByteArray rawHeader(QByteArrayView headerName) const;
|
||||||
|
|
||||||
typedef QPair<QByteArray, QByteArray> RawHeaderPair;
|
typedef QPair<QByteArray, QByteArray> RawHeaderPair;
|
||||||
const QList<RawHeaderPair>& rawHeaderPairs() const;
|
const QList<RawHeaderPair>& rawHeaderPairs() const;
|
||||||
|
@ -1314,7 +1314,7 @@ void QNetworkReplyHttpImplPrivate::checkForRedirect(const int statusCode)
|
|||||||
// What do we do about the caching of the HTML note?
|
// What do we do about the caching of the HTML note?
|
||||||
// The response to a 303 MUST NOT be cached, while the response to
|
// The response to a 303 MUST NOT be cached, while the response to
|
||||||
// all of the others is cacheable if the headers indicate it to be
|
// all of the others is cacheable if the headers indicate it to be
|
||||||
QByteArray header = q->rawHeader("location"_ba);
|
QByteArray header = q->rawHeader("location");
|
||||||
QUrl url = QUrl(QString::fromUtf8(header));
|
QUrl url = QUrl(QString::fromUtf8(header));
|
||||||
if (!url.isValid())
|
if (!url.isValid())
|
||||||
url = QUrl(QLatin1StringView(header));
|
url = QUrl(QLatin1StringView(header));
|
||||||
@ -1358,7 +1358,7 @@ void QNetworkReplyHttpImplPrivate::replyDownloadMetaData(const QList<QPair<QByte
|
|||||||
// A user having manually defined which encodings they accept is, for
|
// A user having manually defined which encodings they accept is, for
|
||||||
// somwehat unknown (presumed legacy compatibility) reasons treated as
|
// somwehat unknown (presumed legacy compatibility) reasons treated as
|
||||||
// disabling our decompression:
|
// disabling our decompression:
|
||||||
const bool autoDecompress = request.rawHeader("accept-encoding"_ba).isEmpty();
|
const bool autoDecompress = request.rawHeader("accept-encoding").isEmpty();
|
||||||
const bool shouldDecompress = isCompressed && autoDecompress;
|
const bool shouldDecompress = isCompressed && autoDecompress;
|
||||||
// reconstruct the HTTP header
|
// reconstruct the HTTP header
|
||||||
for (const auto &[key, originValue] : hm) {
|
for (const auto &[key, originValue] : hm) {
|
||||||
@ -1859,7 +1859,7 @@ bool QNetworkReplyHttpImplPrivate::canResume() const
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Can only resume if server/resource supports Range header.
|
// Can only resume if server/resource supports Range header.
|
||||||
const auto acceptRangesheaderName = "Accept-Ranges"_ba;
|
constexpr auto acceptRangesheaderName = QByteArrayView("Accept-Ranges");
|
||||||
if (!q->hasRawHeader(acceptRangesheaderName) || q->rawHeader(acceptRangesheaderName) == "none")
|
if (!q->hasRawHeader(acceptRangesheaderName) || q->rawHeader(acceptRangesheaderName) == "none")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -617,8 +617,9 @@ void QNetworkRequest::setHeader(KnownHeaders header, const QVariant &value)
|
|||||||
network request.
|
network request.
|
||||||
|
|
||||||
\sa rawHeader(), setRawHeader()
|
\sa rawHeader(), setRawHeader()
|
||||||
|
\note In Qt versions prior to 6.7, this function took QByteArray only.
|
||||||
*/
|
*/
|
||||||
bool QNetworkRequest::hasRawHeader(const QByteArray &headerName) const
|
bool QNetworkRequest::hasRawHeader(QByteArrayView headerName) const
|
||||||
{
|
{
|
||||||
return d->findRawHeader(headerName) != d->rawHeaders.constEnd();
|
return d->findRawHeader(headerName) != d->rawHeaders.constEnd();
|
||||||
}
|
}
|
||||||
@ -632,12 +633,11 @@ bool QNetworkRequest::hasRawHeader(const QByteArray &headerName) const
|
|||||||
Raw headers can be set with setRawHeader() or with setHeader().
|
Raw headers can be set with setRawHeader() or with setHeader().
|
||||||
|
|
||||||
\sa header(), setRawHeader()
|
\sa header(), setRawHeader()
|
||||||
|
\note In Qt versions prior to 6.7, this function took QByteArray only.
|
||||||
*/
|
*/
|
||||||
QByteArray QNetworkRequest::rawHeader(const QByteArray &headerName) const
|
QByteArray QNetworkRequest::rawHeader(QByteArrayView headerName) const
|
||||||
{
|
{
|
||||||
QNetworkHeadersPrivate::RawHeadersList::ConstIterator it =
|
if (const auto it = d->findRawHeader(headerName); it != d->rawHeaders.constEnd())
|
||||||
d->findRawHeader(headerName);
|
|
||||||
if (it != d->rawHeaders.constEnd())
|
|
||||||
return it->second;
|
return it->second;
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
@ -118,9 +118,15 @@ public:
|
|||||||
void setHeader(KnownHeaders header, const QVariant &value);
|
void setHeader(KnownHeaders header, const QVariant &value);
|
||||||
|
|
||||||
// raw headers:
|
// raw headers:
|
||||||
|
#if QT_NETWORK_REMOVED_SINCE(6, 7)
|
||||||
bool hasRawHeader(const QByteArray &headerName) const;
|
bool hasRawHeader(const QByteArray &headerName) const;
|
||||||
|
#endif
|
||||||
|
bool hasRawHeader(QByteArrayView headerName) const;
|
||||||
QList<QByteArray> rawHeaderList() const;
|
QList<QByteArray> rawHeaderList() const;
|
||||||
|
#if QT_NETWORK_REMOVED_SINCE(6, 7)
|
||||||
QByteArray rawHeader(const QByteArray &headerName) const;
|
QByteArray rawHeader(const QByteArray &headerName) const;
|
||||||
|
#endif
|
||||||
|
QByteArray rawHeader(QByteArrayView headerName) const;
|
||||||
void setRawHeader(const QByteArray &headerName, const QByteArray &value);
|
void setRawHeader(const QByteArray &headerName, const QByteArray &value);
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
|
40
src/network/compat/removed_api.cpp
Normal file
40
src/network/compat/removed_api.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// Copyright (c) 2023 LLC «V Kontakte»
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||||
|
|
||||||
|
#define QT_NETWORK_BUILD_REMOVED_API
|
||||||
|
|
||||||
|
#include "qtnetworkglobal.h"
|
||||||
|
|
||||||
|
QT_USE_NAMESPACE
|
||||||
|
|
||||||
|
#if QT_NETWORK_REMOVED_SINCE(6, 7)
|
||||||
|
|
||||||
|
#include "qnetworkreply.h"
|
||||||
|
|
||||||
|
QByteArray QNetworkReply::rawHeader(const QByteArray &headerName) const
|
||||||
|
{
|
||||||
|
return rawHeader(qToByteArrayViewIgnoringNull(headerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QNetworkReply::hasRawHeader(const QByteArray &headerName) const
|
||||||
|
{
|
||||||
|
return hasRawHeader(qToByteArrayViewIgnoringNull(headerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "qnetworkrequest.h"
|
||||||
|
|
||||||
|
QByteArray QNetworkRequest::rawHeader(const QByteArray &headerName) const
|
||||||
|
{
|
||||||
|
return rawHeader(qToByteArrayViewIgnoringNull(headerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QNetworkRequest::hasRawHeader(const QByteArray &headerName) const
|
||||||
|
{
|
||||||
|
return hasRawHeader(qToByteArrayViewIgnoringNull(headerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
// #include "qotherheader.h"
|
||||||
|
// // implement removed functions from qotherheader.h
|
||||||
|
// order sections alphabetically
|
||||||
|
|
||||||
|
#endif // QT_NETWORK_REMOVED_SINCE(6, 7)
|
Loading…
x
Reference in New Issue
Block a user