diff options
Diffstat (limited to 'src/network/access/qnetworkaccessmanager.cpp')
-rw-r--r-- | src/network/access/qnetworkaccessmanager.cpp | 102 |
1 files changed, 80 insertions, 22 deletions
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 76b95b5823..1120446bc7 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -311,6 +311,7 @@ static void ensureInitialized() /*! \fn void QNetworkAccessManager::networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible) + \obsolete This signal is emitted when the value of the \l networkAccessible property changes. \a accessible is the new network accessibility. @@ -320,6 +321,7 @@ static void ensureInitialized() \fn void QNetworkAccessManager::networkSessionConnected() \since 4.7 + \obsolete \internal @@ -1008,10 +1010,11 @@ QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &requ return d_func()->postProcess(createRequest(QNetworkAccessManager::DeleteOperation, request)); } -#ifndef QT_NO_BEARERMANAGEMENT +#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section /*! \since 4.7 + \obsolete Sets the network configuration that will be used when creating the \l {QNetworkSession}{network session} to \a config. @@ -1049,6 +1052,7 @@ void QNetworkAccessManager::setConfiguration(const QNetworkConfiguration &config /*! \since 4.7 + \obsolete Returns the network configuration that will be used to create the \l {QNetworkSession}{network session} which will be used when processing network requests. @@ -1069,6 +1073,7 @@ QNetworkConfiguration QNetworkAccessManager::configuration() const /*! \since 4.7 + \obsolete Returns the current active network configuration. @@ -1097,6 +1102,7 @@ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const /*! \since 4.7 + \obsolete Overrides the reported network accessibility. If \a accessible is NotAccessible the reported network accessiblity will always be NotAccessible. Otherwise the reported network @@ -1109,16 +1115,20 @@ void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkA d->defaultAccessControl = accessible == NotAccessible ? false : true; if (d->networkAccessible != accessible) { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED NetworkAccessibility previous = networkAccessible(); d->networkAccessible = accessible; NetworkAccessibility current = networkAccessible(); if (previous != current) emit networkAccessibleChanged(current); +QT_WARNING_POP } } /*! \since 4.7 + \obsolete Returns the current network accessibility. */ @@ -1240,7 +1250,7 @@ void QNetworkAccessManager::connectToHostEncrypted(const QString &hostName, quin // There is no way to enable SPDY/HTTP2 via a request, so we need to check // the ssl configuration whether SPDY/HTTP2 is allowed here. if (sslConfiguration.allowedNextProtocols().contains(QSslConfiguration::ALPNProtocolHTTP2)) - request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); + request.setAttribute(QNetworkRequest::Http2AllowedAttribute, true); else if (sslConfiguration.allowedNextProtocols().contains(QSslConfiguration::NextProtocolSpdy3_0)) request.setAttribute(QNetworkRequest::SpdyAllowedAttribute, true); @@ -1404,6 +1414,11 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, redirectPolicy()); } +#if QT_CONFIG(http) + if (!req.transferTimeout()) + req.setTransferTimeout(transferTimeout()); +#endif + if (autoDeleteReplies() && req.attribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute).isNull()) { req.setAttribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, true); @@ -1479,7 +1494,7 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera if (!d->statusMonitor.isMonitoring() && !d->statusMonitor.start()) qWarning(lcNetMon, "failed to start network status monitoring"); } else { -#ifndef QT_NO_BEARERMANAGEMENT +#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section // Return a disabled network reply if network access is disabled. // Except if the scheme is empty or file:// or if the host resolves to a loopback address. if (d->networkAccessible == NotAccessible && !isLocalFile) { @@ -1553,7 +1568,7 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera } #endif QNetworkReplyHttpImpl *reply = new QNetworkReplyHttpImpl(this, request, op, outgoingData); -#ifndef QT_NO_BEARERMANAGEMENT +#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section if (!d->statusMonitor.isEnabled()) { connect(this, SIGNAL(networkSessionConnected()), reply, SLOT(_q_networkSessionConnected())); @@ -1565,7 +1580,7 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera // first step: create the reply QNetworkReplyImpl *reply = new QNetworkReplyImpl(this); -#ifndef QT_NO_BEARERMANAGEMENT +#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section // NETMONTODO: network reply impl must be augmented to use the same monitoring // capabilities as http network reply impl does. Once it does: uncomment the condition below if (!isLocalFile /*&& !d->statusMonitor.isEnabled()*/) { @@ -1713,18 +1728,50 @@ void QNetworkAccessManager::setAutoDeleteReplies(bool shouldAutoDelete) d_func()->autoDeleteReplies = shouldAutoDelete; } -void QNetworkAccessManagerPrivate::_q_replyFinished() +/*! + \since 5.15 + + Returns the timeout used for transfers, in milliseconds. + + This timeout is zero if setTransferTimeout() hasn't been + called, which means that the timeout is not used. +*/ +int QNetworkAccessManager::transferTimeout() const +{ + return d_func()->transferTimeout; +} + +/*! + \since 5.15 + + Sets \a timeout as the transfer timeout in milliseconds. + + Transfers are aborted if no bytes are transferred before + the timeout expires. Zero means no timer is set. If no + argument is provided, the timeout is + QNetworkRequest::TransferTimeoutPreset. If this function + is not called, the timeout is disabled and has the + value zero. The request-specific non-zero timeouts set for + the requests that are executed override this value. This means + that if QNetworkAccessManager has an enabled timeout, it needs + to be disabled to execute a request without a timeout. + + \sa transferTimeout() +*/ +void QNetworkAccessManager::setTransferTimeout(int timeout) +{ + d_func()->transferTimeout = timeout; +} + +void QNetworkAccessManagerPrivate::_q_replyFinished(QNetworkReply *reply) { Q_Q(QNetworkAccessManager); - QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender()); - if (reply) { - emit q->finished(reply); - if (reply->request().attribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, false).toBool()) - QMetaObject::invokeMethod(reply, [reply] { reply->deleteLater(); }, Qt::QueuedConnection); - } + emit q->finished(reply); + if (reply->request().attribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, false).toBool()) + QMetaObject::invokeMethod(reply, [reply] { reply->deleteLater(); }, Qt::QueuedConnection); -#ifndef QT_NO_BEARERMANAGEMENT +#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section // If there are no active requests, release our reference to the network session. // It will not be destroyed immediately, but rather when the connection cache is flushed // after 2 minutes. @@ -1734,13 +1781,13 @@ void QNetworkAccessManagerPrivate::_q_replyFinished() #endif } -void QNetworkAccessManagerPrivate::_q_replyEncrypted() +void QNetworkAccessManagerPrivate::_q_replyEncrypted(QNetworkReply *reply) { #ifndef QT_NO_SSL Q_Q(QNetworkAccessManager); - QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender()); - if (reply) - emit q->encrypted(reply); + emit q->encrypted(reply); +#else + Q_UNUSED(reply); #endif } @@ -1772,15 +1819,17 @@ QNetworkReply *QNetworkAccessManagerPrivate::postProcess(QNetworkReply *reply) { Q_Q(QNetworkAccessManager); QNetworkReplyPrivate::setManager(reply, q); - q->connect(reply, SIGNAL(finished()), SLOT(_q_replyFinished())); + q->connect(reply, &QNetworkReply::finished, reply, + [this, reply]() { _q_replyFinished(reply); }); #ifndef QT_NO_SSL /* In case we're compiled without SSL support, we don't have this signal and we need to * avoid getting a connection error. */ - q->connect(reply, SIGNAL(encrypted()), SLOT(_q_replyEncrypted())); + q->connect(reply, &QNetworkReply::encrypted, reply, + [this, reply]() { _q_replyEncrypted(reply); }); q->connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(_q_replySslErrors(QList<QSslError>))); q->connect(reply, SIGNAL(preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)), SLOT(_q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*))); #endif -#ifndef QT_NO_BEARERMANAGEMENT +#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section activeReplyCount++; #endif @@ -1941,7 +1990,7 @@ void QNetworkAccessManagerPrivate::destroyThread() { if (thread) { thread->quit(); - thread->wait(5000); + thread->wait(QDeadlineTimer(5000)); if (thread->isFinished()) delete thread; else @@ -1950,7 +1999,7 @@ void QNetworkAccessManagerPrivate::destroyThread() } } -#ifndef QT_NO_BEARERMANAGEMENT +#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &config) { Q_Q(QNetworkAccessManager); @@ -1985,10 +2034,13 @@ void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &co if (!networkSessionStrongRef) { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED if (networkAccessible == QNetworkAccessManager::NotAccessible || !online) emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible); else emit q->networkAccessibleChanged(QNetworkAccessManager::UnknownAccessibility); +QT_WARNING_POP return; } @@ -2035,6 +2087,8 @@ void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged(QNetworkSession bool reallyOnline = false; //Do not emit the networkSessionConnected signal here, except for roaming -> connected //transition, otherwise it is emitted twice in a row when opening a connection. +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED if (state == QNetworkSession::Connected && lastSessionState != QNetworkSession::Roaming) emit q->networkSessionConnected(); lastSessionState = state; @@ -2070,6 +2124,7 @@ void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged(QNetworkSession _q_networkSessionClosed(); createSession(q->configuration()); } +QT_WARNING_POP } void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline) @@ -2081,6 +2136,8 @@ void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline) return; } +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED // if the user set a config, we only care whether this one is active. // Otherwise, this QNAM is online if there is an online config. @@ -2106,6 +2163,7 @@ void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline) emit q->networkAccessibleChanged(networkAccessible); } } +QT_WARNING_POP } void QNetworkAccessManagerPrivate::_q_configurationChanged(const QNetworkConfiguration &configuration) |