6#include "qplatformdefs.h"
13#include "private/http2protocol_p.h"
16#include "QtCore/qdatetime.h"
17#include "QtCore/qlocale.h"
18#include "QtCore/qshareddata.h"
19#include "QtCore/qtimezone.h"
20#include "QtCore/private/qduplicatetracker_p.h"
21#include "QtCore/private/qtools_p.h"
24#if QT_CONFIG(datestring)
34using namespace std::chrono_literals;
433 static const int maxRedirectCount = 50;
439 , maxRedirectsAllowed(maxRedirectCount)
440 { qRegisterMetaType<QNetworkRequest>(); }
444 delete sslConfiguration;
453 priority =
other.priority;
454 maxRedirectsAllowed =
other.maxRedirectsAllowed;
456 sslConfiguration =
nullptr;
457 if (
other.sslConfiguration)
460 peerVerifyName =
other.peerVerifyName;
462 h1Configuration =
other.h1Configuration;
463 h2Configuration =
other.h2Configuration;
464 decompressedSafetyCheckThreshold =
other.decompressedSafetyCheckThreshold;
466 transferTimeout =
other.transferTimeout;
472 priority ==
other.priority &&
473 attributes ==
other.attributes &&
474 maxRedirectsAllowed ==
other.maxRedirectsAllowed &&
475 peerVerifyName ==
other.peerVerifyName
477 && h1Configuration ==
other.h1Configuration
478 && h2Configuration ==
other.h2Configuration
479 && decompressedSafetyCheckThreshold ==
other.decompressedSafetyCheckThreshold
481 && transferTimeout ==
other.transferTimeout
497 qint64 decompressedSafetyCheckThreshold = 10ll * 1024ll * 1024ll;
499 std::chrono::milliseconds transferTimeout = 0ms;
519 d->h2Configuration.setServerPushEnabled(
false);
925 return d->h1Configuration;
936 d->h1Configuration = configuration;
962 return d->h2Configuration;
980 d->h2Configuration = configuration;
993qint64 QNetworkRequest::decompressedSafetyCheckThreshold()
const
995 return d->decompressedSafetyCheckThreshold;
1020void QNetworkRequest::setDecompressedSafetyCheckThreshold(
qint64 threshold)
1022 d->decompressedSafetyCheckThreshold = threshold;
1026#if QT_CONFIG(http) || defined (Q_OS_WASM)
1056std::chrono::milliseconds QNetworkRequest::transferTimeoutAsDuration()
const
1075void QNetworkRequest::setTransferTimeout(std::chrono::milliseconds duration)
1088constexpr bool operator<(
const HeaderPair &lhs,
const HeaderPair &rhs)
1090 return lhs.wellKnownHeader < rhs.wellKnownHeader;
1095 return lhs.wellKnownHeader < rhs;
1100 return lhs < rhs.wellKnownHeader;
1128 return std::nullopt;
1129 return it->knownHeader;
1134 auto pred = [
key](
const HeaderPair &pair) {
return pair.knownHeader ==
key; };
1137 return std::nullopt;
1138 return it->wellKnownHeader;
1158 const QList<QNetworkCookie> *cookies = get_if<QList<QNetworkCookie>>(&
value);
1175 return value.toByteArray();
1178 switch (
value.userType()) {
1179 case QMetaType::QUrl:
1180 return value.toUrl().toEncoded();
1183 return value.toByteArray();
1188 switch (
value.userType()) {
1190 case QMetaType::QDate:
1192 case QMetaType::QDateTime:
1196 return value.toByteArray();
1206 Q_UNREACHABLE_RETURN({});
1212 if (headerName.isEmpty())
1221 if (is(
"content-type"))
1223 else if (is(
"content-length"))
1225 else if (is(
"cookie"))
1227 else if (is(
"content-disposition"))
1237 if (is(
"if-modified-since"))
1241 if (is(
"if-none-match"))
1248 else if (is(
"last-modified"))
1253 if (is(
"set-cookie"))
1255 else if (is(
"server"))
1260 if (is(
"user-agent"))
1278 QList<QNetworkCookie>
result;
1281 if (parsed.size() != 1)
1293 if (!trimmed.startsWith(
'"') && !trimmed.startsWith(R
"(W/")"))
1296 if (!trimmed.endsWith(
'"'))
1306 if (trimmedRaw ==
"*")
1311 if (
const auto trimmed = element.trimmed(); op(trimmed))
1379 Q_UNREACHABLE_RETURN({});
1407 QList<QNetworkCookie>
res;
1429template<
class HeaderName>
1462 QList<QByteArray>
result;
1469 if (seen.hasSeen(
name))
1486 const char* separator =
"";
1489 result.append(separator);
1506 invalidateHeaderCache();
1513 if (!wellKnownOpt) {
1515 qWarning(
"QNetworkRequest::setHeader: invalid header value KnownHeader(%d) received",
header);
1519 if (
value.isNull()) {
1525 qWarning(
"QNetworkRequest::setHeader: QVariant of type %s cannot be used with header %s",
1535 invalidateHeaderCache();
1547 invalidateHeaderCache();
1554 invalidateHeaderCache();
1564 parseAndSetHeader(knownHeaderOpt.value(),
value);
1566 invalidateHeaderCache();
1573 invalidateHeaderCache();
1580 if (parsedKeyAsInt != -1) {
1583 parseAndSetHeader(parsedKey,
value);
1590 if (
value.isNull()) {
1606 switch (month_str[0]) {
1608 switch (month_str[1]) {
1612 switch (month_str[2] ) {
1623 switch (month_str[2] ) {
1631 switch (month_str[1]) {
1661#if QT_CONFIG(datestring)
1670 int day, year, hour, minute, second;
1673 if (sscanf_s(
value.constData(),
"%*3s, %d %3s %d %d:%d:%d 'GMT'", &day, month_name, 4, &year, &hour, &minute, &second) == 6)
1677 if (sscanf(
value.constData(),
"%*3s, %d %3s %d %d:%d:%d 'GMT'", &day, month_name, &year, &hour, &minute, &second) == 6)
1685 dt =
c.toDateTime(sansWeekday,
"dd-MMM-yy hh:mm:ss 'GMT'"_L1);
1697 return QLocale::c().toString(dt.toUTC(), u
"ddd, dd MMM yyyy hh:mm:ss 'GMT'").toLatin1();
1707 QHash<QByteArray, qsizetype> nameToIndex;
1719 if (
auto it = nameToIndex.find(
name);
it != nameToIndex.end()) {
1739 for (
const auto &[
key,
value] : raw) {
1757 return std::nullopt;
1763 return std::nullopt;
1767 const QList<QByteArray> &
values)
1770 return std::nullopt;
1772 QList<QNetworkCookie> cookies;
1776 if (cookies.empty())
1777 return std::nullopt;
1787 const QList<QByteArray> &
values)
1790 return std::nullopt;
1792 QList<QNetworkCookie> cookies;
1796 if (cookies.empty())
1797 return std::nullopt;
1801void QNetworkHeadersPrivate::invalidateHeaderCache()
1807void QNetworkHeadersPrivate::setCookedFromHttp(
const QHttpHeaders &newHeaders)
1811 QMap<QNetworkRequest::KnownHeaders, QList<QByteArray>> multipleHeadersMap;
1812 for (
int i = 0;
i < newHeaders.size(); ++
i) {
1813 const auto name = newHeaders.nameAt(
i);
1814 const auto value = newHeaders.valueAt(
i);
1817 if (parsedKeyAsInt == -1)
1823 auto &
list = multipleHeadersMap[parsedKey];
1827 for (
auto i = multipleHeadersMap.cbegin(),
end = multipleHeadersMap.cend();
i !=
end; ++
i)
1833#include "moc_qnetworkrequest.cpp"
static Q_CORE_EXPORT int compare(QAnyStringView lhs, QAnyStringView rhs, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
Compares the string view lhs with the string view rhs and returns a negative integer if lhs is less t...
bool startsWith(QByteArrayView other) const noexcept
qlonglong toLongLong(bool *ok=nullptr, int base=10) const
bool endsWith(QByteArrayView other) const noexcept
constexpr qsizetype size() const noexcept
constexpr void chop(qsizetype n)
QByteArrayView trimmed() const noexcept
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
\inmodule QtCore\reentrant
\inmodule QtCore \reentrant
bool remove(const Key &key)
Removes the item that has the key from the hash.
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
T value(const Key &key) const noexcept
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
The QHttp1Configuration class controls HTTP/1 parameters and settings.
The QHttp2Configuration class controls HTTP/2 parameters and settings.
constexpr auto tokenize(Needle &&needle, Flags...flags) const noexcept(noexcept(qTokenize(std::declval< const QLatin1StringView & >(), std::forward< Needle >(needle), flags...))) -> decltype(qTokenize(*this, std::forward< Needle >(needle), flags...))
qsizetype size() const noexcept
reference emplaceBack(Args &&... args)
void reserve(qsizetype size)
void append(parameter_type t)
static QLocale c()
Returns a QLocale object initialized to the "C" locale.
The QNetworkCookie class holds one network cookie.
static QList< QNetworkCookie > parseCookies(QByteArrayView cookieString)
Parses the cookie string cookieString as received from a server response in the "Set-Cookie:" header.
RawForm
This enum is used with the toRawForm() function to declare which form of a cookie shall be returned.
\variable QNetworkRequest::DefaultTransferTimeout
~QNetworkRequestPrivate()
std::chrono::milliseconds transferTimeout
QSslConfiguration * sslConfiguration
bool operator==(const QNetworkRequestPrivate &other) const
QNetworkRequest::Priority priority
QNetworkRequestPrivate(const QNetworkRequestPrivate &other)
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
bool operator==(const QNetworkRequest &other) const
Returns true if this object is the same as other (i.e., if they have the same URL,...
void setOriginatingObject(QObject *object)
KnownHeaders
List of known header types that QNetworkRequest parses.
@ ContentDispositionHeader
void setHeaders(const QHttpHeaders &newHeaders)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setSslConfiguration(const QSslConfiguration &configuration)
Sets this network request's SSL configuration to be config.
~QNetworkRequest()
Disposes of the QNetworkRequest object.
void setHeader(KnownHeaders header, const QVariant &value)
Sets the value of the known header header to be value, overriding any previously set headers.
bool hasRawHeader(QAnyStringView headerName) const
Returns true if the raw header headerName is present in this network request.
void setAttribute(Attribute code, const QVariant &value)
Sets the attribute associated with code code to be value value.
Priority priority() const
QVariant attribute(Attribute code, const QVariant &defaultValue=QVariant()) const
Returns the attribute associated with the code code.
QVariant header(KnownHeaders header) const
Returns the value of the known network header header if it is present in this request.
void setRawHeader(const QByteArray &headerName, const QByteArray &value)
Sets the header headerName to be of value headerValue.
QNetworkRequest()
Constructs a QNetworkRequest object with no URL to be requested.
QObject * originatingObject() const
static constexpr auto DefaultTransferTimeout
int maximumRedirectsAllowed() const
QByteArray rawHeader(QAnyStringView headerName) const
Returns the raw form of header headerName.
QList< QByteArray > rawHeaderList() const
Returns a list of all raw headers that are set in this network request.
QNetworkRequest & operator=(QNetworkRequest &&other) noexcept
void setPeerVerifyName(const QString &peerName)
QHttpHeaders headers() const
void setMaximumRedirectsAllowed(int maximumRedirectsAllowed)
void setUrl(const QUrl &url)
Sets the URL this network request is referring to be url.
QUrl url() const
Returns the URL this network request is referring to.
void setPriority(Priority priority)
QString peerVerifyName() const
QSslConfiguration sslConfiguration() const
Returns this network request's SSL configuration.
T * data() const noexcept
The QSslConfiguration class holds the configuration and state of an SSL connection.
static QSslConfiguration defaultConfiguration()
Returns the default SSL configuration to be used in new SSL connections.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore \reentrant
static QUrl fromEncoded(QByteArrayView input, ParsingMode mode=TolerantMode)
Parses input and returns the corresponding QUrl.
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
QSet< QString >::iterator it
const qint32 qtDefaultStreamReceiveWindowSize
const qint32 maxSessionReceiveWindowSize((quint32(1)<< 31) - 1)
Combined button and popup list for selecting options.
constexpr char toAsciiLower(char ch) noexcept
constexpr bool is_sorted(ForwardIterator first, ForwardIterator last, BinaryPredicate p={})
QList< QString > QStringList
Constructs a string list that contains the given string, str.
static QString header(const QString &name)
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static int parseHeaderName(const QByteArray &headerName)
static int name_to_month(const char *month_str)
static QStringList parseMatchImpl(QByteArrayView raw, T op)
static constexpr HeaderPair knownHeadersArr[]
static bool isSetCookie(QByteArrayView name)
static QList< QNetworkCookie > parseCookieHeader(QByteArrayView raw)
static int parseHeaderName(QByteArrayView headerName)
static std::optional< QNetworkRequest::KnownHeaders > toKnownHeader(QHttpHeaders::WellKnownHeader key)
static QVariant parseETag(QByteArrayView raw)
static QVariant parseHeaderValue(QNetworkRequest::KnownHeaders header, QByteArrayView value)
static QVariant parseHttpDate(QByteArrayView raw)
static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVariant &value)
static QByteArray makeCookieHeader(const QList< QNetworkCookie > &cookies, QNetworkCookie::RawForm type, QByteArrayView separator)
static QStringList parseIfMatch(QByteArrayView raw)
static QStringList parseIfNoneMatch(QByteArrayView raw)
static void setFromRawHeader(QHttpHeaders &headers, HeaderName header, QByteArrayView value)
static std::optional< QHttpHeaders::WellKnownHeader > toWellKnownHeader(QNetworkRequest::KnownHeaders key)
GLenum GLsizei GLsizei GLint * values
[15]
static bool operator<(const QSettingsIniKey &k1, const QSettingsIniKey &k2)
#define QStringLiteral(str)
QUrl url("example.com")
[constructor-url-reference]