summaryrefslogtreecommitdiffstats
path: root/src/network/access/qnetworkaccessmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/access/qnetworkaccessmanager.cpp')
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp67
1 files changed, 52 insertions, 15 deletions
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index 76b95b5823..1f05fd931f 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -1240,7 +1240,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 +1404,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);
@@ -1713,16 +1718,48 @@ 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
// If there are no active requests, release our reference to the network session.
@@ -1734,13 +1771,11 @@ 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);
#endif
}
@@ -1772,11 +1807,13 @@ 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
@@ -1941,7 +1978,7 @@ void QNetworkAccessManagerPrivate::destroyThread()
{
if (thread) {
thread->quit();
- thread->wait(5000);
+ thread->wait(QDeadlineTimer(5000));
if (thread->isFinished())
delete thread;
else