Remove bearermanagement usage inside QNAM and QNetworkProxy
Change-Id: I2c4fdf598b46daf1b69a65848ebe0fd78ef8be24 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
ab91ac0992
commit
4888e3e840
@ -317,10 +317,6 @@ void QFtpDTP::connectToHost(const QString & host, quint16 port)
|
||||
socket = nullptr;
|
||||
}
|
||||
socket = new QTcpSocket(this);
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
//copy network session down to the socket
|
||||
socket->setProperty("_q_networksession", property("_q_networksession"));
|
||||
#endif
|
||||
socket->setObjectName(QLatin1String("QFtpDTP Passive state socket"));
|
||||
connect(socket, SIGNAL(connected()), SLOT(socketConnected()));
|
||||
connect(socket, SIGNAL(readyRead()), SLOT(socketReadyRead()));
|
||||
@ -333,10 +329,6 @@ void QFtpDTP::connectToHost(const QString & host, quint16 port)
|
||||
|
||||
int QFtpDTP::setupListener(const QHostAddress &address)
|
||||
{
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
//copy network session down to the socket
|
||||
listener.setProperty("_q_networksession", property("_q_networksession"));
|
||||
#endif
|
||||
if (!listener.isListening() && !listener.listen(address, 0))
|
||||
return -1;
|
||||
return listener.serverPort();
|
||||
@ -819,11 +811,6 @@ QFtpPI::QFtpPI(QObject *parent) :
|
||||
void QFtpPI::connectToHost(const QString &host, quint16 port)
|
||||
{
|
||||
emit connectState(QFtp::HostLookup);
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
//copy network session down to the socket & DTP
|
||||
commandSocket.setProperty("_q_networksession", property("_q_networksession"));
|
||||
dtp.setProperty("_q_networksession", property("_q_networksession"));
|
||||
#endif
|
||||
commandSocket.connectToHost(host, port);
|
||||
}
|
||||
|
||||
@ -2290,10 +2277,6 @@ void QFtpPrivate::_q_startNextCommand()
|
||||
c->rawCmds.clear();
|
||||
_q_piFinished(QLatin1String("Proxy set to ") + proxyHost + QLatin1Char(':') + QString::number(proxyPort));
|
||||
} else if (c->command == QFtp::ConnectToHost) {
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
//copy network session down to the PI
|
||||
pi.setProperty("_q_networksession", q->property("_q_networksession"));
|
||||
#endif
|
||||
if (!proxyHost.isEmpty()) {
|
||||
host = c->rawCmds.at(0);
|
||||
port = c->rawCmds.at(1).toUInt();
|
||||
|
@ -132,10 +132,6 @@ void QHttpNetworkConnectionPrivate::init()
|
||||
for (int i = 0; i < channelCount; i++) {
|
||||
channels[i].setConnection(this->q_func());
|
||||
channels[i].ssl = encrypt;
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
//push session down to channels
|
||||
channels[i].networkSession = networkSession;
|
||||
#endif
|
||||
}
|
||||
|
||||
delayedConnectionTimer.setSingleShot(true);
|
||||
@ -1267,19 +1263,6 @@ void QHttpNetworkConnectionPrivate::startNetworkLayerStateLookup()
|
||||
channels[1].networkLayerPreference = QAbstractSocket::IPv6Protocol;
|
||||
|
||||
int timeout = 300;
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
if (networkSession) {
|
||||
const QNetworkConfiguration::BearerType bearerType = networkSession->configuration().bearerType();
|
||||
if (bearerType == QNetworkConfiguration::Bearer2G)
|
||||
timeout = 800;
|
||||
else if (bearerType == QNetworkConfiguration::BearerCDMA2000)
|
||||
timeout = 500;
|
||||
else if (bearerType == QNetworkConfiguration::BearerWCDMA)
|
||||
timeout = 500;
|
||||
else if (bearerType == QNetworkConfiguration::BearerHSPA)
|
||||
timeout = 400;
|
||||
}
|
||||
#endif
|
||||
delayedConnectionTimer.start(timeout);
|
||||
if (delayIpv4)
|
||||
channels[1].ensureConnection();
|
||||
@ -1309,37 +1292,6 @@ void QHttpNetworkConnectionPrivate::_q_connectDelayedChannel()
|
||||
channels[1].ensureConnection();
|
||||
}
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt,
|
||||
QHttpNetworkConnection::ConnectionType connectionType,
|
||||
QObject *parent, QSharedPointer<QNetworkSession> networkSession)
|
||||
: QObject(*(new QHttpNetworkConnectionPrivate(hostName, port, encrypt, connectionType)), parent)
|
||||
{
|
||||
Q_D(QHttpNetworkConnection);
|
||||
d->networkSession = std::move(networkSession);
|
||||
d->init();
|
||||
if (QNetworkStatusMonitor::isEnabled()) {
|
||||
connect(&d->connectionMonitor, &QNetworkConnectionMonitor::reachabilityChanged,
|
||||
this, &QHttpNetworkConnection::onlineStateChanged, Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
|
||||
QHttpNetworkConnection::QHttpNetworkConnection(quint16 connectionCount, const QString &hostName,
|
||||
quint16 port, bool encrypt, QObject *parent,
|
||||
QSharedPointer<QNetworkSession> networkSession,
|
||||
QHttpNetworkConnection::ConnectionType connectionType)
|
||||
: QObject(*(new QHttpNetworkConnectionPrivate(connectionCount, hostName, port, encrypt,
|
||||
connectionType)), parent)
|
||||
{
|
||||
Q_D(QHttpNetworkConnection);
|
||||
d->networkSession = std::move(networkSession);
|
||||
d->init();
|
||||
if (QNetworkStatusMonitor::isEnabled()) {
|
||||
connect(&d->connectionMonitor, &QNetworkConnectionMonitor::reachabilityChanged,
|
||||
this, &QHttpNetworkConnection::onlineStateChanged, Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
#else
|
||||
QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt,
|
||||
QHttpNetworkConnection::ConnectionType connectionType, QObject *parent)
|
||||
: QObject(*(new QHttpNetworkConnectionPrivate(hostName, port, encrypt , connectionType)), parent)
|
||||
@ -1365,7 +1317,6 @@ QHttpNetworkConnection::QHttpNetworkConnection(quint16 connectionCount, const QS
|
||||
this, &QHttpNetworkConnection::onlineStateChanged, Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
#endif // QT_NO_BEARERMANAGEMENT
|
||||
|
||||
QHttpNetworkConnection::~QHttpNetworkConnection()
|
||||
{
|
||||
|
@ -55,7 +55,6 @@
|
||||
#include <QtNetwork/qnetworkrequest.h>
|
||||
#include <QtNetwork/qnetworkreply.h>
|
||||
#include <QtNetwork/qabstractsocket.h>
|
||||
#include <QtNetwork/qnetworksession.h>
|
||||
|
||||
#include <qhttp2configuration.h>
|
||||
|
||||
@ -100,23 +99,12 @@ public:
|
||||
ConnectionTypeHTTP2Direct
|
||||
};
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
explicit QHttpNetworkConnection(const QString &hostName, quint16 port = 80, bool encrypt = false,
|
||||
ConnectionType connectionType = ConnectionTypeHTTP,
|
||||
QObject *parent = nullptr, QSharedPointer<QNetworkSession> networkSession
|
||||
= QSharedPointer<QNetworkSession>());
|
||||
QHttpNetworkConnection(quint16 channelCount, const QString &hostName, quint16 port = 80,
|
||||
bool encrypt = false, QObject *parent = nullptr,
|
||||
QSharedPointer<QNetworkSession> networkSession = QSharedPointer<QNetworkSession>(),
|
||||
ConnectionType connectionType = ConnectionTypeHTTP);
|
||||
#else
|
||||
explicit QHttpNetworkConnection(const QString &hostName, quint16 port = 80, bool encrypt = false,
|
||||
ConnectionType connectionType = ConnectionTypeHTTP,
|
||||
QObject *parent = 0);
|
||||
QHttpNetworkConnection(quint16 channelCount, const QString &hostName, quint16 port = 80,
|
||||
bool encrypt = false, QObject *parent = 0,
|
||||
ConnectionType connectionType = ConnectionTypeHTTP);
|
||||
#endif
|
||||
~QHttpNetworkConnection();
|
||||
|
||||
//The hostname to which this is connected to.
|
||||
@ -290,10 +278,6 @@ public:
|
||||
QSharedPointer<QSslContext> sslContext;
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
QSharedPointer<QNetworkSession> networkSession;
|
||||
#endif
|
||||
|
||||
QHttp2Configuration http2Parameters;
|
||||
|
||||
QString peerVerifyName;
|
||||
|
@ -56,10 +56,6 @@
|
||||
# include <QtNetwork/qsslcipher.h>
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
#include "private/qnetworksession_p.h"
|
||||
#endif
|
||||
|
||||
#include "private/qnetconmonitor_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -123,11 +119,6 @@ void QHttpNetworkConnectionChannel::init()
|
||||
#else
|
||||
socket = new QTcpSocket;
|
||||
#endif
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
//push session down to socket
|
||||
if (networkSession)
|
||||
socket->setProperty("_q_networksession", QVariant::fromValue(networkSession));
|
||||
#endif
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
// Set by QNAM anyway, but let's be safe here
|
||||
socket->setProxy(QNetworkProxy::NoProxy);
|
||||
|
@ -136,9 +136,6 @@ public:
|
||||
#endif
|
||||
// to emit the signal for all in-flight replies:
|
||||
void emitFinishedWithError(QNetworkReply::NetworkError error, const char *message);
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
QSharedPointer<QNetworkSession> networkSession;
|
||||
#endif
|
||||
|
||||
// HTTP pipelining -> http://en.wikipedia.org/wiki/Http_pipelining
|
||||
enum PipeliningSupport {
|
||||
|
@ -181,17 +181,9 @@ class QNetworkAccessCachedHttpConnection: public QHttpNetworkConnection,
|
||||
{
|
||||
// Q_OBJECT
|
||||
public:
|
||||
#ifdef QT_NO_BEARERMANAGEMENT
|
||||
QNetworkAccessCachedHttpConnection(const QString &hostName, quint16 port, bool encrypt,
|
||||
QHttpNetworkConnection::ConnectionType connectionType)
|
||||
: QHttpNetworkConnection(hostName, port, encrypt, connectionType)
|
||||
#else // ### Qt6: Remove section
|
||||
QNetworkAccessCachedHttpConnection(const QString &hostName, quint16 port, bool encrypt,
|
||||
QHttpNetworkConnection::ConnectionType connectionType,
|
||||
QSharedPointer<QNetworkSession> networkSession)
|
||||
: QHttpNetworkConnection(hostName, port, encrypt, connectionType, /*parent=*/nullptr,
|
||||
std::move(networkSession))
|
||||
#endif
|
||||
{
|
||||
setExpires(true);
|
||||
setShareable(true);
|
||||
@ -334,14 +326,8 @@ void QHttpThreadDelegate::startRequest()
|
||||
if (!httpConnection) {
|
||||
// no entry in cache; create an object
|
||||
// the http object is actually a QHttpNetworkConnection
|
||||
#ifdef QT_NO_BEARERMANAGEMENT
|
||||
httpConnection = new QNetworkAccessCachedHttpConnection(urlCopy.host(), urlCopy.port(), ssl,
|
||||
connectionType);
|
||||
#else // ### Qt6: Remove section
|
||||
httpConnection = new QNetworkAccessCachedHttpConnection(urlCopy.host(), urlCopy.port(), ssl,
|
||||
connectionType,
|
||||
networkSession);
|
||||
#endif // QT_NO_BEARERMANAGEMENT
|
||||
if (connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2
|
||||
|| connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2Direct) {
|
||||
httpConnection->setHttp2Parameters(http2Parameters);
|
||||
|
@ -118,9 +118,6 @@ public:
|
||||
QNetworkReply::NetworkError incomingErrorCode;
|
||||
QString incomingErrorDetail;
|
||||
QHttp2Configuration http2Parameters;
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
QSharedPointer<QNetworkSession> networkSession;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// The zerocopy download buffer, if used:
|
||||
|
@ -39,13 +39,11 @@
|
||||
|
||||
#include "qnetworkaccessbackend_p.h"
|
||||
#include "qnetworkaccessmanager_p.h"
|
||||
#include "qnetworkconfigmanager.h"
|
||||
#include "qnetworkrequest.h"
|
||||
#include "qnetworkreply.h"
|
||||
#include "qnetworkreply_p.h"
|
||||
#include "QtCore/qmutex.h"
|
||||
#include "QtCore/qstringlist.h"
|
||||
#include "QtNetwork/private/qnetworksession_p.h"
|
||||
|
||||
#include "qnetworkaccesscachebackend_p.h"
|
||||
#include "qabstractnetworkcache.h"
|
||||
@ -371,30 +369,6 @@ void QNetworkAccessBackend::sslErrors(const QList<QSslError> &errors)
|
||||
*/
|
||||
bool QNetworkAccessBackend::start()
|
||||
{
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
// For bearer, check if session start is required
|
||||
QSharedPointer<QNetworkSession> networkSession(manager->getNetworkSession());
|
||||
if (networkSession) {
|
||||
// session required
|
||||
if (networkSession->isOpen() &&
|
||||
networkSession->state() == QNetworkSession::Connected) {
|
||||
// Session is already open and ready to use.
|
||||
// copy network session down to the backend
|
||||
setProperty("_q_networksession", QVariant::fromValue(networkSession));
|
||||
} else {
|
||||
// Session not ready, but can skip for loopback connections
|
||||
|
||||
// This is not ideal.
|
||||
// Don't need an open session for localhost access.
|
||||
if (!reply->url.isLocalFile()) {
|
||||
const QString host = reply->url.host();
|
||||
if (host != QLatin1String("localhost") && !QHostAddress(host).isLoopback())
|
||||
return false; // need to wait for session to be opened
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
reply->proxyList = manager->queryProxy(QNetworkProxyQuery(url()));
|
||||
#endif
|
||||
|
@ -161,10 +161,6 @@ void QNetworkAccessFtpBackend::open()
|
||||
if (!objectCache->requestEntry(cacheKey, this,
|
||||
SLOT(ftpConnectionReady(QNetworkAccessCache::CacheableObject*)))) {
|
||||
ftp = new QNetworkAccessCachedFtpConnection;
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
//copy network session down to the QFtp
|
||||
ftp->setProperty("_q_networksession", property("_q_networksession"));
|
||||
#endif
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
if (proxy.type() == QNetworkProxy::FtpCachingProxy)
|
||||
ftp->setProxy(proxy.hostName(), proxy.port());
|
||||
|
@ -54,9 +54,6 @@
|
||||
#include "qhstsstore_p.h"
|
||||
#endif // QT_CONFIG(settings)
|
||||
|
||||
#include "QtNetwork/qnetworksession.h"
|
||||
#include "QtNetwork/private/qsharednetworksession_p.h"
|
||||
|
||||
#if QT_CONFIG(ftp)
|
||||
#include "qnetworkaccessftpbackend_p.h"
|
||||
#endif
|
||||
@ -71,7 +68,6 @@
|
||||
#include "QtCore/qvector.h"
|
||||
#include "QtNetwork/private/qauthenticator_p.h"
|
||||
#include "QtNetwork/qsslconfiguration.h"
|
||||
#include "QtNetwork/qnetworkconfigmanager.h"
|
||||
#include "QtNetwork/private/http2protocol_p.h"
|
||||
|
||||
#if QT_CONFIG(http)
|
||||
@ -479,20 +475,7 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent)
|
||||
if (QNetworkStatusMonitor::isEnabled()) {
|
||||
connect(&d->statusMonitor, SIGNAL(onlineStateChanged(bool)),
|
||||
SLOT(_q_onlineStateChanged(bool)));
|
||||
#ifdef QT_NO_BEARERMANAGEMENT
|
||||
d->networkAccessible = d->statusMonitor.isNetworkAccessible();
|
||||
#else
|
||||
d->networkAccessible = d->statusMonitor.isNetworkAccessible() ? Accessible : NotAccessible;
|
||||
} else {
|
||||
// if a session is required, we track online state through
|
||||
// the QNetworkSession's signals if a request is already made.
|
||||
// we need to track current accessibility state by default
|
||||
//
|
||||
connect(&d->networkConfigurationManager, SIGNAL(onlineStateChanged(bool)),
|
||||
SLOT(_q_onlineStateChanged(bool)));
|
||||
connect(&d->networkConfigurationManager, SIGNAL(configurationChanged(QNetworkConfiguration)),
|
||||
SLOT(_q_configurationChanged(QNetworkConfiguration)));
|
||||
#endif // QT_NO_BEARERMANAGEMENT
|
||||
}
|
||||
}
|
||||
|
||||
@ -993,186 +976,6 @@ QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &requ
|
||||
return d_func()->postProcess(createRequest(QNetworkAccessManager::DeleteOperation, request));
|
||||
}
|
||||
|
||||
#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.
|
||||
|
||||
The network configuration is used to create and open a network session before any request that
|
||||
requires network access is process. If no network configuration is explicitly set via this
|
||||
function the network configuration returned by
|
||||
QNetworkConfigurationManager::defaultConfiguration() will be used.
|
||||
|
||||
To restore the default network configuration set the network configuration to the value
|
||||
returned from QNetworkConfigurationManager::defaultConfiguration().
|
||||
|
||||
Setting a network configuration means that the QNetworkAccessManager instance will only
|
||||
be using the specified one. In particular, if the default network configuration changes
|
||||
(upon e.g. Wifi being available), this new configuration needs to be enabled
|
||||
manually if desired.
|
||||
|
||||
\snippet code/src_network_access_qnetworkaccessmanager.cpp 2
|
||||
|
||||
If an invalid network configuration is set, a network session will not be created. In this
|
||||
case network requests will be processed regardless, but may fail. For example:
|
||||
|
||||
\snippet code/src_network_access_qnetworkaccessmanager.cpp 3
|
||||
|
||||
\sa configuration(), QNetworkSession
|
||||
*/
|
||||
void QNetworkAccessManager::setConfiguration(const QNetworkConfiguration &config)
|
||||
{
|
||||
Q_D(QNetworkAccessManager);
|
||||
|
||||
d->networkConfiguration = config;
|
||||
d->customNetworkConfiguration = true;
|
||||
d->createSession(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.
|
||||
|
||||
\sa setConfiguration(), activeConfiguration()
|
||||
*/
|
||||
QNetworkConfiguration QNetworkAccessManager::configuration() const
|
||||
{
|
||||
Q_D(const QNetworkAccessManager);
|
||||
|
||||
QSharedPointer<QNetworkSession> session(d->getNetworkSession());
|
||||
if (session && !d->statusMonitor.isEnabled()) {
|
||||
return session->configuration();
|
||||
} else {
|
||||
return d->networkConfigurationManager.defaultConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 4.7
|
||||
\obsolete
|
||||
|
||||
Returns the current active network configuration.
|
||||
|
||||
If the network configuration returned by configuration() is of type
|
||||
QNetworkConfiguration::ServiceNetwork this function will return the current active child
|
||||
network configuration of that configuration. Otherwise returns the same network configuration
|
||||
as configuration().
|
||||
|
||||
Use this function to return the actual network configuration currently in use by the network
|
||||
session.
|
||||
|
||||
\sa configuration()
|
||||
*/
|
||||
QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const
|
||||
{
|
||||
Q_D(const QNetworkAccessManager);
|
||||
|
||||
QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession());
|
||||
if (networkSession && !d->statusMonitor.isEnabled()) {
|
||||
return d->networkConfigurationManager.configurationFromIdentifier(
|
||||
networkSession->sessionProperty(QLatin1String("ActiveConfiguration")).toString());
|
||||
} else {
|
||||
return d->networkConfigurationManager.defaultConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\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
|
||||
accessibility will reflect the actual device state.
|
||||
*/
|
||||
void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkAccessibility accessible)
|
||||
{
|
||||
Q_D(QNetworkAccessManager);
|
||||
|
||||
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.
|
||||
*/
|
||||
QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccessible() const
|
||||
{
|
||||
Q_D(const QNetworkAccessManager);
|
||||
|
||||
if (d->statusMonitor.isEnabled()) {
|
||||
if (!d->statusMonitor.isMonitoring())
|
||||
d->statusMonitor.start();
|
||||
return d->networkAccessible;
|
||||
}
|
||||
|
||||
if (d->customNetworkConfiguration && d->networkConfiguration.state().testFlag(QNetworkConfiguration::Undefined))
|
||||
return UnknownAccessibility;
|
||||
|
||||
if (d->networkSessionRequired) {
|
||||
QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession());
|
||||
if (networkSession) {
|
||||
// d->online holds online/offline state of this network session.
|
||||
if (d->online)
|
||||
return d->networkAccessible;
|
||||
else
|
||||
return NotAccessible;
|
||||
} else {
|
||||
if (d->defaultAccessControl) {
|
||||
if (d->online)
|
||||
return d->networkAccessible;
|
||||
else
|
||||
return NotAccessible;
|
||||
}
|
||||
return (d->networkAccessible);
|
||||
}
|
||||
} else {
|
||||
if (d->online)
|
||||
return d->networkAccessible;
|
||||
else
|
||||
return NotAccessible;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
||||
Returns the network session currently in use.
|
||||
This can be changed at any time, ownership remains with the QNetworkAccessManager
|
||||
*/
|
||||
const QWeakPointer<const QNetworkSession> QNetworkAccessManagerPrivate::getNetworkSession(const QNetworkAccessManager *q)
|
||||
{
|
||||
return q->d_func()->networkSessionWeakRef;
|
||||
}
|
||||
|
||||
QSharedPointer<QNetworkSession> QNetworkAccessManagerPrivate::getNetworkSession() const
|
||||
{
|
||||
if (networkSessionStrongRef)
|
||||
return networkSessionStrongRef;
|
||||
return networkSessionWeakRef.toStrongRef();
|
||||
}
|
||||
|
||||
#endif // QT_NO_BEARERMANAGEMENT
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
/*!
|
||||
\since 5.2
|
||||
@ -1457,12 +1260,7 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
|
||||
// See the code in ctor - QNetworkStatusMonitor allows us to
|
||||
// immediately set 'networkAccessible' even before we start
|
||||
// the monitor.
|
||||
#ifdef QT_NO_BEARERMANAGEMENT
|
||||
if (!d->networkAccessible
|
||||
#else
|
||||
if (d->networkAccessible == NotAccessible
|
||||
#endif // QT_NO_BEARERMANAGEMENT
|
||||
&& !isLocalFile) {
|
||||
if (!d->networkAccessible && !isLocalFile) {
|
||||
QHostAddress dest;
|
||||
QString host = req.url().host().toLower();
|
||||
if (!(dest.setAddress(host) && dest.isLoopback())
|
||||
@ -1474,35 +1272,6 @@ 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 // ### 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) {
|
||||
QHostAddress dest;
|
||||
QString host = req.url().host().toLower();
|
||||
if (!(dest.setAddress(host) && dest.isLoopback()) && host != QLatin1String("localhost")
|
||||
&& host != QHostInfo::localHostName().toLower()) {
|
||||
return new QDisabledNetworkReply(this, req, op);
|
||||
}
|
||||
}
|
||||
|
||||
if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.identifier().isEmpty())) {
|
||||
if (!d->networkConfiguration.identifier().isEmpty()) {
|
||||
if ((d->networkConfiguration.state() & QNetworkConfiguration::Defined)
|
||||
&& d->networkConfiguration != d->networkConfigurationManager.defaultConfiguration())
|
||||
d->createSession(d->networkConfigurationManager.defaultConfiguration());
|
||||
else
|
||||
d->createSession(d->networkConfiguration);
|
||||
|
||||
} else {
|
||||
if (d->networkSessionRequired)
|
||||
d->createSession(d->networkConfigurationManager.defaultConfiguration());
|
||||
else
|
||||
d->initializeSession = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
QNetworkRequest request = req;
|
||||
@ -1549,26 +1318,12 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
|
||||
}
|
||||
#endif
|
||||
QNetworkReplyHttpImpl *reply = new QNetworkReplyHttpImpl(this, request, op, outgoingData);
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
if (!d->statusMonitor.isEnabled()) {
|
||||
connect(this, SIGNAL(networkSessionConnected()),
|
||||
reply, SLOT(_q_networkSessionConnected()));
|
||||
}
|
||||
#endif
|
||||
return reply;
|
||||
}
|
||||
#endif // QT_CONFIG(http)
|
||||
|
||||
// first step: create the reply
|
||||
QNetworkReplyImpl *reply = new QNetworkReplyImpl(this);
|
||||
#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()*/) {
|
||||
connect(this, SIGNAL(networkSessionConnected()),
|
||||
reply, SLOT(_q_networkSessionConnected()));
|
||||
}
|
||||
#endif
|
||||
QNetworkReplyImplPrivate *priv = reply->d_func();
|
||||
priv->manager = this;
|
||||
|
||||
@ -1751,15 +1506,6 @@ void QNetworkAccessManagerPrivate::_q_replyFinished(QNetworkReply *reply)
|
||||
emit q->finished(reply);
|
||||
if (reply->request().attribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, false).toBool())
|
||||
QMetaObject::invokeMethod(reply, [reply] { reply->deleteLater(); }, Qt::QueuedConnection);
|
||||
|
||||
#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.
|
||||
activeReplyCount--;
|
||||
if (networkSessionStrongRef && activeReplyCount == 0)
|
||||
networkSessionStrongRef.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
void QNetworkAccessManagerPrivate::_q_replyEncrypted(QNetworkReply *reply)
|
||||
@ -1810,9 +1556,6 @@ QNetworkReply *QNetworkAccessManagerPrivate::postProcess(QNetworkReply *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 // ### Qt6: Remove section
|
||||
activeReplyCount++;
|
||||
#endif
|
||||
|
||||
return reply;
|
||||
}
|
||||
@ -1980,233 +1723,11 @@ void QNetworkAccessManagerPrivate::destroyThread()
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &config)
|
||||
{
|
||||
Q_Q(QNetworkAccessManager);
|
||||
|
||||
initializeSession = false;
|
||||
|
||||
//resurrect weak ref if possible
|
||||
networkSessionStrongRef = networkSessionWeakRef.toStrongRef();
|
||||
|
||||
QSharedPointer<QNetworkSession> newSession;
|
||||
if (config.isValid())
|
||||
newSession = QSharedNetworkSessionManager::getSession(config);
|
||||
|
||||
QNetworkSession::State oldState = QNetworkSession::Invalid;
|
||||
if (networkSessionStrongRef) {
|
||||
//do nothing if new and old session are the same
|
||||
if (networkSessionStrongRef == newSession)
|
||||
return;
|
||||
//disconnect from old session
|
||||
QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(opened()), q, SIGNAL(networkSessionConnected()));
|
||||
QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(closed()), q, SLOT(_q_networkSessionClosed()));
|
||||
QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(stateChanged(QNetworkSession::State)),
|
||||
q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)));
|
||||
QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(error(QNetworkSession::SessionError)),
|
||||
q, SLOT(_q_networkSessionFailed(QNetworkSession::SessionError)));
|
||||
oldState = networkSessionStrongRef->state();
|
||||
}
|
||||
|
||||
//switch to new session (null if config was invalid)
|
||||
networkSessionStrongRef = newSession;
|
||||
networkSessionWeakRef = networkSessionStrongRef.toWeakRef();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//connect to new session
|
||||
QObject::connect(networkSessionStrongRef.data(), SIGNAL(opened()), q, SIGNAL(networkSessionConnected()), Qt::QueuedConnection);
|
||||
//QueuedConnection is used to avoid deleting the networkSession inside its closed signal
|
||||
QObject::connect(networkSessionStrongRef.data(), SIGNAL(closed()), q, SLOT(_q_networkSessionClosed()), Qt::QueuedConnection);
|
||||
QObject::connect(networkSessionStrongRef.data(), SIGNAL(stateChanged(QNetworkSession::State)),
|
||||
q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)), Qt::QueuedConnection);
|
||||
QObject::connect(networkSessionStrongRef.data(), SIGNAL(error(QNetworkSession::SessionError)),
|
||||
q, SLOT(_q_networkSessionFailed(QNetworkSession::SessionError)));
|
||||
|
||||
const QNetworkSession::State newState = networkSessionStrongRef->state();
|
||||
if (newState != oldState) {
|
||||
QMetaObject::invokeMethod(q, "_q_networkSessionStateChanged", Qt::QueuedConnection,
|
||||
Q_ARG(QNetworkSession::State, newState));
|
||||
}
|
||||
}
|
||||
|
||||
void QNetworkAccessManagerPrivate::_q_networkSessionClosed()
|
||||
{
|
||||
Q_Q(QNetworkAccessManager);
|
||||
QSharedPointer<QNetworkSession> networkSession(getNetworkSession());
|
||||
if (networkSession) {
|
||||
networkConfiguration = networkSession->configuration();
|
||||
|
||||
//disconnect from old session
|
||||
QObject::disconnect(networkSession.data(), SIGNAL(opened()), q, SIGNAL(networkSessionConnected()));
|
||||
QObject::disconnect(networkSession.data(), SIGNAL(closed()), q, SLOT(_q_networkSessionClosed()));
|
||||
QObject::disconnect(networkSession.data(), SIGNAL(stateChanged(QNetworkSession::State)),
|
||||
q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)));
|
||||
QObject::disconnect(networkSession.data(), SIGNAL(error(QNetworkSession::SessionError)),
|
||||
q, SLOT(_q_networkSessionFailed(QNetworkSession::SessionError)));
|
||||
|
||||
networkSessionStrongRef.clear();
|
||||
networkSessionWeakRef.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged(QNetworkSession::State state)
|
||||
{
|
||||
Q_Q(QNetworkAccessManager);
|
||||
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;
|
||||
|
||||
if (online && (state == QNetworkSession::Disconnected
|
||||
|| state == QNetworkSession::NotAvailable)) {
|
||||
const auto cfgs = networkConfigurationManager.allConfigurations();
|
||||
for (const QNetworkConfiguration &cfg : cfgs) {
|
||||
if (cfg.state().testFlag(QNetworkConfiguration::Active)) {
|
||||
reallyOnline = true;
|
||||
}
|
||||
}
|
||||
} else if (state == QNetworkSession::Connected || state == QNetworkSession::Roaming) {
|
||||
reallyOnline = true;
|
||||
}
|
||||
online = reallyOnline;
|
||||
|
||||
if (!reallyOnline) {
|
||||
if (state != QNetworkSession::Connected && state != QNetworkSession::Roaming) {
|
||||
if (networkAccessible != QNetworkAccessManager::NotAccessible) {
|
||||
networkAccessible = QNetworkAccessManager::NotAccessible;
|
||||
emit q->networkAccessibleChanged(networkAccessible);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (defaultAccessControl)
|
||||
if (networkAccessible != QNetworkAccessManager::Accessible) {
|
||||
networkAccessible = QNetworkAccessManager::Accessible;
|
||||
emit q->networkAccessibleChanged(networkAccessible);
|
||||
}
|
||||
}
|
||||
if (online && (state != QNetworkSession::Connected && state != QNetworkSession::Roaming)) {
|
||||
_q_networkSessionClosed();
|
||||
createSession(q->configuration());
|
||||
}
|
||||
QT_WARNING_POP
|
||||
}
|
||||
|
||||
void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline)
|
||||
{
|
||||
Q_Q(QNetworkAccessManager);
|
||||
|
||||
if (statusMonitor.isEnabled()) {
|
||||
networkAccessible = isOnline ? QNetworkAccessManager::Accessible : QNetworkAccessManager::NotAccessible;
|
||||
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.
|
||||
if (customNetworkConfiguration) {
|
||||
online = (networkConfiguration.state() & QNetworkConfiguration::Active);
|
||||
} else {
|
||||
if (online != isOnline) {
|
||||
online = isOnline;
|
||||
_q_networkSessionClosed();
|
||||
createSession(q->configuration());
|
||||
}
|
||||
}
|
||||
if (online) {
|
||||
if (defaultAccessControl) {
|
||||
if (networkAccessible != QNetworkAccessManager::Accessible) {
|
||||
networkAccessible = QNetworkAccessManager::Accessible;
|
||||
emit q->networkAccessibleChanged(networkAccessible);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (networkAccessible != QNetworkAccessManager::NotAccessible) {
|
||||
networkAccessible = QNetworkAccessManager::NotAccessible;
|
||||
emit q->networkAccessibleChanged(networkAccessible);
|
||||
}
|
||||
}
|
||||
QT_WARNING_POP
|
||||
}
|
||||
|
||||
void QNetworkAccessManagerPrivate::_q_configurationChanged(const QNetworkConfiguration &configuration)
|
||||
{
|
||||
if (statusMonitor.isEnabled())
|
||||
return;
|
||||
|
||||
const QString id = configuration.identifier();
|
||||
if (configuration.state().testFlag(QNetworkConfiguration::Active)) {
|
||||
if (!onlineConfigurations.contains(id)) {
|
||||
QSharedPointer<QNetworkSession> session(getNetworkSession());
|
||||
if (session) {
|
||||
if (online && session->configuration().identifier()
|
||||
!= networkConfigurationManager.defaultConfiguration().identifier()) {
|
||||
|
||||
onlineConfigurations.insert(id);
|
||||
// CHECK: If it's having Active flag - why would it be disconnected ???
|
||||
//this one disconnected but another one is online,
|
||||
// close and create new session
|
||||
_q_networkSessionClosed();
|
||||
createSession(networkConfigurationManager.defaultConfiguration());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (onlineConfigurations.contains(id)) {
|
||||
//this one is disconnecting
|
||||
// CHECK: If it disconnected while we create a session over a down configuration ???
|
||||
onlineConfigurations.remove(id);
|
||||
if (!onlineConfigurations.isEmpty()) {
|
||||
_q_networkSessionClosed();
|
||||
createSession(configuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QNetworkAccessManagerPrivate::_q_networkSessionFailed(QNetworkSession::SessionError)
|
||||
{
|
||||
if (statusMonitor.isEnabled())
|
||||
return;
|
||||
|
||||
const auto cfgs = networkConfigurationManager.allConfigurations();
|
||||
for (const QNetworkConfiguration &cfg : cfgs) {
|
||||
if (cfg.state().testFlag(QNetworkConfiguration::Active)) {
|
||||
online = true;
|
||||
_q_networkSessionClosed();
|
||||
createSession(networkConfigurationManager.defaultConfiguration());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline)
|
||||
{
|
||||
networkAccessible = isOnline;
|
||||
}
|
||||
|
||||
#endif // QT_NO_BEARERMANAGEMENT
|
||||
|
||||
#if QT_CONFIG(http)
|
||||
QNetworkRequest QNetworkAccessManagerPrivate::prepareMultipart(const QNetworkRequest &request, QHttpMultiPart *multiPart)
|
||||
{
|
||||
|
@ -63,9 +63,6 @@ class QNetworkProxy;
|
||||
class QNetworkProxyFactory;
|
||||
class QSslError;
|
||||
class QHstsPolicy;
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
class QNetworkConfiguration;
|
||||
#endif
|
||||
class QHttpMultiPart;
|
||||
|
||||
class QNetworkReplyImplPrivate;
|
||||
@ -74,9 +71,6 @@ class Q_NETWORK_EXPORT QNetworkAccessManager: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
Q_PROPERTY(NetworkAccessibility networkAccessible READ networkAccessible WRITE setNetworkAccessible NOTIFY networkAccessibleChanged)
|
||||
#endif
|
||||
|
||||
public:
|
||||
enum Operation {
|
||||
@ -90,18 +84,6 @@ public:
|
||||
UnknownOperation = 0
|
||||
};
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
enum QT_DEPRECATED_NETWORK_API_5_15 NetworkAccessibility {
|
||||
UnknownAccessibility = -1,
|
||||
NotAccessible = 0,
|
||||
Accessible = 1
|
||||
};
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
Q_ENUM(NetworkAccessibility)
|
||||
QT_WARNING_POP
|
||||
#endif
|
||||
|
||||
explicit QNetworkAccessManager(QObject *parent = nullptr);
|
||||
~QNetworkAccessManager();
|
||||
|
||||
@ -148,18 +130,6 @@ QT_WARNING_POP
|
||||
QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QHttpMultiPart *multiPart);
|
||||
#endif
|
||||
|
||||
#if !defined(QT_NO_BEARERMANAGEMENT) // ### Qt6: Remove section
|
||||
QT_DEPRECATED_VERSION_5_15 void setConfiguration(const QNetworkConfiguration &config);
|
||||
QT_DEPRECATED_VERSION_5_15 QNetworkConfiguration configuration() const;
|
||||
QT_DEPRECATED_VERSION_5_15 QNetworkConfiguration activeConfiguration() const;
|
||||
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
QT_DEPRECATED_VERSION_5_15 void setNetworkAccessible(NetworkAccessibility accessible);
|
||||
QT_DEPRECATED_VERSION_5_15 NetworkAccessibility networkAccessible() const;
|
||||
QT_WARNING_POP
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
void connectToHostEncrypted(const QString &hostName, quint16 port = 443,
|
||||
const QSslConfiguration &sslConfiguration = QSslConfiguration::defaultConfiguration());
|
||||
@ -190,19 +160,6 @@ Q_SIGNALS:
|
||||
void preSharedKeyAuthenticationRequired(QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator);
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
QT_DEPRECATED_VERSION_5_15 void networkSessionConnected();
|
||||
|
||||
#ifndef Q_MOC_RUN // moc has trouble with the expansion of these macros
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
#endif
|
||||
QT_DEPRECATED_VERSION_5_15 void networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible);
|
||||
#ifndef Q_MOC_RUN // moc has trouble with the expansion of these macros
|
||||
QT_WARNING_POP
|
||||
#endif
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request,
|
||||
QIODevice *outgoingData = nullptr);
|
||||
@ -222,12 +179,6 @@ private:
|
||||
Q_DECLARE_PRIVATE(QNetworkAccessManager)
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList<QSslError>))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*))
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionClosed())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionStateChanged(QNetworkSession::State))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_configurationChanged(const QNetworkConfiguration &))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionFailed(QNetworkSession::SessionError))
|
||||
#endif
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_onlineStateChanged(bool))
|
||||
};
|
||||
|
||||
|
@ -60,11 +60,7 @@
|
||||
#include "qhsts_p.h"
|
||||
#include "private/qobject_p.h"
|
||||
#include "QtNetwork/qnetworkproxy.h"
|
||||
#include "QtNetwork/qnetworksession.h"
|
||||
#include "qnetworkaccessauthenticationmanager_p.h"
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
#include "QtNetwork/qnetworkconfigmanager.h"
|
||||
#endif
|
||||
|
||||
#if QT_CONFIG(settings)
|
||||
#include "qhstsstore_p.h"
|
||||
@ -86,34 +82,12 @@ public:
|
||||
thread(nullptr),
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
proxyFactory(nullptr),
|
||||
#endif
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
lastSessionState(QNetworkSession::Invalid),
|
||||
networkConfiguration(networkConfigurationManager.defaultConfiguration()),
|
||||
customNetworkConfiguration(false),
|
||||
networkSessionRequired(networkConfigurationManager.capabilities()
|
||||
& QNetworkConfigurationManager::NetworkSessionRequired),
|
||||
activeReplyCount(0),
|
||||
online(false),
|
||||
initializeSession(true),
|
||||
#endif
|
||||
cookieJarCreated(false),
|
||||
defaultAccessControl(true),
|
||||
redirectPolicy(QNetworkRequest::ManualRedirectPolicy),
|
||||
authenticationManager(QSharedPointer<QNetworkAccessAuthenticationManager>::create())
|
||||
{
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
// we would need all active configurations to check for
|
||||
// d->networkConfigurationManager.isOnline(), which is asynchronous
|
||||
// and potentially expensive. We can just check the configuration here
|
||||
online = (networkConfiguration.state().testFlag(QNetworkConfiguration::Active));
|
||||
if (online)
|
||||
networkAccessible = QNetworkAccessManager::Accessible;
|
||||
else if (networkConfiguration.state().testFlag(QNetworkConfiguration::Undefined))
|
||||
networkAccessible = QNetworkAccessManager::UnknownAccessibility;
|
||||
else
|
||||
networkAccessible = QNetworkAccessManager::NotAccessible;
|
||||
#endif
|
||||
}
|
||||
~QNetworkAccessManagerPrivate();
|
||||
|
||||
@ -153,21 +127,6 @@ public:
|
||||
QStringList backendSupportedSchemes() const;
|
||||
|
||||
void _q_onlineStateChanged(bool isOnline);
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
void createSession(const QNetworkConfiguration &config);
|
||||
QSharedPointer<QNetworkSession> getNetworkSession() const;
|
||||
|
||||
void _q_networkSessionClosed();
|
||||
void _q_networkSessionNewConfigurationActivated();
|
||||
void _q_networkSessionPreferredConfigurationChanged(const QNetworkConfiguration &config,
|
||||
bool isSeamless);
|
||||
void _q_networkSessionStateChanged(QNetworkSession::State state);
|
||||
|
||||
void _q_configurationChanged(const QNetworkConfiguration &configuration);
|
||||
void _q_networkSessionFailed(QNetworkSession::SessionError error);
|
||||
|
||||
QSet<QString> onlineConfigurations;
|
||||
#endif
|
||||
|
||||
#if QT_CONFIG(http)
|
||||
QNetworkRequest prepareMultipart(const QNetworkRequest &request, QHttpMultiPart *multiPart);
|
||||
@ -186,23 +145,7 @@ public:
|
||||
QNetworkProxyFactory *proxyFactory;
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
QSharedPointer<QNetworkSession> networkSessionStrongRef;
|
||||
QWeakPointer<QNetworkSession> networkSessionWeakRef;
|
||||
QNetworkSession::State lastSessionState;
|
||||
QNetworkConfigurationManager networkConfigurationManager;
|
||||
QNetworkConfiguration networkConfiguration;
|
||||
// we need to track whether the user set a config or not,
|
||||
// because the default config might change
|
||||
bool customNetworkConfiguration;
|
||||
bool networkSessionRequired;
|
||||
QNetworkAccessManager::NetworkAccessibility networkAccessible;
|
||||
int activeReplyCount;
|
||||
bool online;
|
||||
bool initializeSession;
|
||||
#else
|
||||
bool networkAccessible = true;
|
||||
#endif
|
||||
|
||||
bool cookieJarCreated;
|
||||
bool defaultAccessControl;
|
||||
@ -231,9 +174,6 @@ public:
|
||||
|
||||
int transferTimeout = 0;
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
Q_AUTOTEST_EXPORT static const QWeakPointer<const QNetworkSession> getNetworkSession(const QNetworkAccessManager *manager);
|
||||
#endif
|
||||
Q_DECLARE_PUBLIC(QNetworkAccessManager)
|
||||
};
|
||||
|
||||
|
@ -164,21 +164,6 @@ static QHash<QByteArray, QByteArray> parseHttpOptionHeader(const QByteArray &hea
|
||||
}
|
||||
}
|
||||
|
||||
#if QT_CONFIG(bearermanagement) // ### Qt6: Remove section
|
||||
static bool isSessionNeeded(const QUrl &url)
|
||||
{
|
||||
if (QNetworkStatusMonitor::isEnabled()) {
|
||||
// In case QNetworkStatus/QNetConManager are in business,
|
||||
// no session, no bearer manager are involved.
|
||||
return false;
|
||||
}
|
||||
// Connections to the local machine does not require a session
|
||||
QString host = url.host().toLower();
|
||||
return !QHostAddress(host).isLoopback() && host != QLatin1String("localhost")
|
||||
&& host != QSysInfo::machineHostName().toLower();
|
||||
}
|
||||
#endif // bearer management
|
||||
|
||||
QNetworkReplyHttpImpl::QNetworkReplyHttpImpl(QNetworkAccessManager* const manager,
|
||||
const QNetworkRequest& request,
|
||||
QNetworkAccessManager::Operation& operation,
|
||||
@ -798,10 +783,6 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq
|
||||
QHttpThreadDelegate *delegate = new QHttpThreadDelegate;
|
||||
// Propagate Http/2 settings:
|
||||
delegate->http2Parameters = request.http2Configuration();
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
if (!QNetworkStatusMonitor::isEnabled())
|
||||
delegate->networkSession = managerPrivate->getNetworkSession();
|
||||
#endif
|
||||
|
||||
// For the synchronous HTTP, this is the normal way the delegate gets deleted
|
||||
// For the asynchronous HTTP this is a safety measure, the delegate deletes itself when HTTP is finished
|
||||
@ -1206,24 +1187,6 @@ void QNetworkReplyHttpImplPrivate::followRedirect()
|
||||
if (managerPrivate->thread)
|
||||
managerPrivate->thread->disconnect();
|
||||
|
||||
#if QT_CONFIG(bearermanagement) // ### Qt6: Remove section
|
||||
// If the original request didn't need a session (i.e. it was to localhost)
|
||||
// then we might not have a session open, to which to redirect, if the
|
||||
// new URL is remote. When this happens, we need to open the session now:
|
||||
if (isSessionNeeded(url)) {
|
||||
if (auto session = managerPrivate->getNetworkSession()) {
|
||||
if (session->state() != QNetworkSession::State::Connected || !session->isOpen()) {
|
||||
startWaitForSession(session);
|
||||
// Need to set 'request' to the redirectRequest so that when QNAM restarts
|
||||
// the request after the session starts it will not repeat the previous request.
|
||||
request = redirectRequest;
|
||||
// Return now, QNAM will start the request when the session has started.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // bearer management
|
||||
|
||||
QMetaObject::invokeMethod(q, "start", Qt::QueuedConnection,
|
||||
Q_ARG(QNetworkRequest, redirectRequest));
|
||||
}
|
||||
@ -1782,69 +1745,10 @@ void QNetworkReplyHttpImplPrivate::setResumeOffset(quint64 offset)
|
||||
*/
|
||||
bool QNetworkReplyHttpImplPrivate::start(const QNetworkRequest &newHttpRequest)
|
||||
{
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
QSharedPointer<QNetworkSession> networkSession(managerPrivate->getNetworkSession());
|
||||
if (!networkSession || QNetworkStatusMonitor::isEnabled()) {
|
||||
#endif
|
||||
postRequest(newHttpRequest);
|
||||
return true;
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
}
|
||||
|
||||
// This is not ideal.
|
||||
if (!isSessionNeeded(url)) {
|
||||
// Don't need to check for an open session if we don't need one.
|
||||
postRequest(newHttpRequest);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (networkSession->isOpen() &&
|
||||
networkSession->state() == QNetworkSession::Connected) {
|
||||
Q_Q(QNetworkReplyHttpImpl);
|
||||
QObject::connect(networkSession.data(), SIGNAL(usagePoliciesChanged(QNetworkSession::UsagePolicies)),
|
||||
q, SLOT(_q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies)));
|
||||
postRequest(newHttpRequest);
|
||||
return true;
|
||||
} else if (synchronous) {
|
||||
// Command line applications using the synchronous path such as xmlpatterns may need an extra push.
|
||||
networkSession->open();
|
||||
if (networkSession->waitForOpened()) {
|
||||
postRequest(newHttpRequest);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
postRequest(newHttpRequest);
|
||||
return true;
|
||||
}
|
||||
|
||||
#if QT_CONFIG(bearermanagement) // ### Qt6: Remove section
|
||||
bool QNetworkReplyHttpImplPrivate::startWaitForSession(QSharedPointer<QNetworkSession> &session)
|
||||
{
|
||||
Q_Q(QNetworkReplyHttpImpl);
|
||||
state = WaitingForSession;
|
||||
|
||||
if (session) {
|
||||
QObject::connect(session.data(), SIGNAL(error(QNetworkSession::SessionError)),
|
||||
q, SLOT(_q_networkSessionFailed()), Qt::QueuedConnection);
|
||||
|
||||
if (!session->isOpen()) {
|
||||
QVariant isBackground = request.attribute(QNetworkRequest::BackgroundRequestAttribute,
|
||||
QVariant::fromValue(false));
|
||||
session->setSessionProperty(QStringLiteral("ConnectInBackground"), isBackground);
|
||||
session->open();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const Qt::ConnectionType connection = synchronous ? Qt::DirectConnection : Qt::QueuedConnection;
|
||||
qWarning("Backend is waiting for QNetworkSession to connect, but there is none!");
|
||||
QMetaObject::invokeMethod(q, "_q_error", connection,
|
||||
Q_ARG(QNetworkReply::NetworkError, QNetworkReply::NetworkSessionFailedError),
|
||||
Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "Network session error.")));
|
||||
QMetaObject::invokeMethod(q, "_q_finished", connection);
|
||||
return false;
|
||||
}
|
||||
#endif // QT_CONFIG(bearermanagement)
|
||||
|
||||
void QNetworkReplyHttpImplPrivate::_q_startOperation()
|
||||
{
|
||||
Q_Q(QNetworkReplyHttpImpl);
|
||||
@ -1853,31 +1757,7 @@ void QNetworkReplyHttpImplPrivate::_q_startOperation()
|
||||
|
||||
state = Working;
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
// Do not start background requests if they are not allowed by session policy
|
||||
QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession());
|
||||
QVariant isBackground = request.attribute(QNetworkRequest::BackgroundRequestAttribute, QVariant::fromValue(false));
|
||||
if (isBackground.toBool() && session && session->usagePolicies().testFlag(QNetworkSession::NoBackgroundTrafficPolicy)) {
|
||||
QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection,
|
||||
Q_ARG(QNetworkReply::NetworkError, QNetworkReply::BackgroundRequestNotAllowedError),
|
||||
Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "Background request not allowed.")));
|
||||
QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!start(request)) {
|
||||
// backend failed to start because the session state is not Connected.
|
||||
// QNetworkAccessManager will call reply->backend->start() again for us when the session
|
||||
// state changes.
|
||||
if (!startWaitForSession(session))
|
||||
return;
|
||||
} else if (session && !QNetworkStatusMonitor::isEnabled()) {
|
||||
QObject::connect(session.data(), SIGNAL(stateChanged(QNetworkSession::State)),
|
||||
q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)),
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
#else
|
||||
if (!start(request)) {
|
||||
if (!start(request)) { // @todo next commit: cleanup, start now always returns true
|
||||
qWarning("Backend start failed");
|
||||
QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection,
|
||||
Q_ARG(QNetworkReply::NetworkError, QNetworkReply::UnknownNetworkError),
|
||||
@ -1885,7 +1765,6 @@ void QNetworkReplyHttpImplPrivate::_q_startOperation()
|
||||
QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection);
|
||||
return;
|
||||
}
|
||||
#endif // QT_NO_BEARERMANAGEMENT
|
||||
|
||||
setupTransferTimeout();
|
||||
if (synchronous) {
|
||||
@ -2049,80 +1928,6 @@ void QNetworkReplyHttpImplPrivate::setupTransferTimeout()
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
void QNetworkReplyHttpImplPrivate::_q_networkSessionConnected()
|
||||
{
|
||||
Q_Q(QNetworkReplyHttpImpl);
|
||||
Q_ASSERT(managerPrivate);
|
||||
|
||||
QSharedPointer<QNetworkSession> session = managerPrivate->getNetworkSession();
|
||||
if (!session)
|
||||
return;
|
||||
|
||||
if (session->state() != QNetworkSession::Connected)
|
||||
return;
|
||||
|
||||
switch (state) {
|
||||
case QNetworkReplyPrivate::Buffering:
|
||||
case QNetworkReplyPrivate::Working:
|
||||
case QNetworkReplyPrivate::Reconnecting:
|
||||
// Migrate existing downloads to new network connection.
|
||||
migrateBackend();
|
||||
break;
|
||||
case QNetworkReplyPrivate::WaitingForSession:
|
||||
// Start waiting requests.
|
||||
QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void QNetworkReplyHttpImplPrivate::_q_networkSessionStateChanged(QNetworkSession::State sessionState)
|
||||
{
|
||||
if (sessionState == QNetworkSession::Disconnected
|
||||
&& state != Idle && state != Reconnecting) {
|
||||
error(QNetworkReplyImpl::NetworkSessionFailedError,
|
||||
QCoreApplication::translate("QNetworkReply", "Network session error."));
|
||||
finished();
|
||||
}
|
||||
}
|
||||
|
||||
void QNetworkReplyHttpImplPrivate::_q_networkSessionFailed()
|
||||
{
|
||||
// Abort waiting and working replies.
|
||||
if (state == WaitingForSession || state == Working) {
|
||||
state = Working;
|
||||
QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession());
|
||||
QString errorStr;
|
||||
if (session)
|
||||
errorStr = session->errorString();
|
||||
else
|
||||
errorStr = QCoreApplication::translate("QNetworkReply", "Network session error.");
|
||||
error(QNetworkReplyImpl::NetworkSessionFailedError, errorStr);
|
||||
finished();
|
||||
}
|
||||
}
|
||||
|
||||
void QNetworkReplyHttpImplPrivate::_q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies newPolicies)
|
||||
{
|
||||
if (request.attribute(QNetworkRequest::BackgroundRequestAttribute).toBool()) {
|
||||
if (newPolicies & QNetworkSession::NoBackgroundTrafficPolicy) {
|
||||
// Abort waiting and working replies.
|
||||
if (state == WaitingForSession || state == Working) {
|
||||
state = Working;
|
||||
error(QNetworkReply::BackgroundRequestNotAllowedError,
|
||||
QCoreApplication::translate("QNetworkReply", "Background request not allowed."));
|
||||
finished();
|
||||
}
|
||||
// ### if canResume(), then we could resume automatically
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// need to have this function since the reply is a private member variable
|
||||
// and the special backends need to access this.
|
||||
void QNetworkReplyHttpImplPrivate::emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal)
|
||||
@ -2185,28 +1990,6 @@ void QNetworkReplyHttpImplPrivate::finished()
|
||||
if (preMigrationDownloaded != Q_INT64_C(-1))
|
||||
totalSize = totalSize.toLongLong() + preMigrationDownloaded;
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
Q_ASSERT(managerPrivate);
|
||||
QSharedPointer<QNetworkSession> session = managerPrivate->getNetworkSession();
|
||||
if (!QNetworkStatusMonitor::isEnabled() && session && session->state() == QNetworkSession::Roaming &&
|
||||
state == Working && errorCode != QNetworkReply::OperationCanceledError) {
|
||||
// only content with a known size will fail with a temporary network failure error
|
||||
if (!totalSize.isNull()) {
|
||||
if (bytesDownloaded != totalSize) {
|
||||
if (migrateBackend()) {
|
||||
// either we are migrating or the request is finished/aborted
|
||||
if (state == Reconnecting || state == WaitingForSession) {
|
||||
return; // exit early if we are migrating.
|
||||
}
|
||||
} else {
|
||||
error(QNetworkReply::TemporaryNetworkFailureError,
|
||||
QNetworkReply::tr("Temporary network failure."));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// if we don't know the total size of or we received everything save the cache
|
||||
if (totalSize.isNull() || totalSize == -1 || bytesDownloaded == totalSize)
|
||||
completeCacheSave();
|
||||
|
@ -66,7 +66,6 @@
|
||||
#include <private/qhttpnetworkrequest_p.h>
|
||||
#include <private/qnetworkreply_p.h>
|
||||
#include <QtNetwork/QNetworkProxy>
|
||||
#include <QtNetwork/QNetworkSession> // ### Qt6: Remove include
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
#include <QtNetwork/QSslConfiguration>
|
||||
@ -102,12 +101,6 @@ public:
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingData())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingDataFinished())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_transferTimedOut())
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionConnected())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionFailed())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionStateChanged(QNetworkSession::State))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies))
|
||||
#endif
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_finished())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_error(QNetworkReply::NetworkError, const QString &))
|
||||
|
||||
@ -162,10 +155,6 @@ signals:
|
||||
|
||||
class QNetworkReplyHttpImplPrivate: public QNetworkReplyPrivate
|
||||
{
|
||||
#if QT_CONFIG(bearermanagement) // ### Qt6: Remove section
|
||||
bool startWaitForSession(QSharedPointer<QNetworkSession> &session);
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
static QHttpNetworkRequest::Priority convert(const QNetworkRequest::Priority& prio);
|
||||
@ -186,12 +175,6 @@ public:
|
||||
void _q_transferTimedOut();
|
||||
void setupTransferTimeout();
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
void _q_networkSessionConnected();
|
||||
void _q_networkSessionFailed();
|
||||
void _q_networkSessionStateChanged(QNetworkSession::State);
|
||||
void _q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies);
|
||||
#endif
|
||||
void _q_finished();
|
||||
|
||||
void finished();
|
||||
|
@ -45,7 +45,6 @@
|
||||
#include "QtCore/qcoreapplication.h"
|
||||
#include "QtCore/qdatetime.h"
|
||||
#include "QtNetwork/qsslconfiguration.h"
|
||||
#include "QtNetwork/qnetworksession.h" // ### Qt6: Remove include
|
||||
#include "qnetworkaccessmanager_p.h"
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
@ -81,6 +80,7 @@ void QNetworkReplyImplPrivate::_q_startOperation()
|
||||
// note: if that method is called directly, it cannot happen that the backend is 0,
|
||||
// because we just checked via a qobject_cast that we got a http backend (see
|
||||
// QNetworkReplyImplPrivate::setup())
|
||||
qDebug() << "backend:" << backend; // @temp
|
||||
if (!backend) {
|
||||
error(QNetworkReplyImpl::ProtocolUnknownError,
|
||||
QCoreApplication::translate("QNetworkReply", "Protocol \"%1\" is unknown").arg(url.scheme())); // not really true!;
|
||||
@ -88,66 +88,15 @@ void QNetworkReplyImplPrivate::_q_startOperation()
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
Q_Q(QNetworkReplyImpl);
|
||||
// Do not start background requests if they are not allowed by session policy
|
||||
QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession());
|
||||
QVariant isBackground = backend->request().attribute(QNetworkRequest::BackgroundRequestAttribute, QVariant::fromValue(false));
|
||||
if (isBackground.toBool() && session && session->usagePolicies().testFlag(QNetworkSession::NoBackgroundTrafficPolicy)) {
|
||||
error(QNetworkReply::BackgroundRequestNotAllowedError,
|
||||
QCoreApplication::translate("QNetworkReply", "Background request not allowed."));
|
||||
finished();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!backend->start()) {
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
// backend failed to start because the session state is not Connected.
|
||||
// QNetworkAccessManager will call _q_startOperation again for us when the session
|
||||
// state changes.
|
||||
state = WaitingForSession;
|
||||
|
||||
if (session) {
|
||||
QObject::connect(session.data(), SIGNAL(error(QNetworkSession::SessionError)),
|
||||
q, SLOT(_q_networkSessionFailed()));
|
||||
|
||||
if (!session->isOpen()) {
|
||||
session->setSessionProperty(QStringLiteral("ConnectInBackground"), isBackground);
|
||||
session->open();
|
||||
}
|
||||
} else {
|
||||
qWarning("Backend is waiting for QNetworkSession to connect, but there is none!");
|
||||
state = Working;
|
||||
error(QNetworkReplyImpl::NetworkSessionFailedError,
|
||||
QCoreApplication::translate("QNetworkReply", "Network session error."));
|
||||
finished();
|
||||
}
|
||||
#else
|
||||
qWarning("Backend start failed");
|
||||
state = Working;
|
||||
error(QNetworkReplyImpl::UnknownNetworkError,
|
||||
QCoreApplication::translate("QNetworkReply", "backend start error."));
|
||||
finished();
|
||||
#endif
|
||||
return;
|
||||
} else {
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
if (session) {
|
||||
QObject::connect(session.data(), SIGNAL(stateChanged(QNetworkSession::State)),
|
||||
q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)), Qt::QueuedConnection);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
if (session) {
|
||||
//get notification of policy changes.
|
||||
QObject::connect(session.data(), SIGNAL(usagePoliciesChanged(QNetworkSession::UsagePolicies)),
|
||||
q, SLOT(_q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies)));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Prepare timer for progress notifications
|
||||
downloadProgressSignalChoke.start();
|
||||
uploadProgressSignalChoke.invalidate();
|
||||
@ -287,80 +236,6 @@ void QNetworkReplyImplPrivate::_q_bufferOutgoingData()
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
void QNetworkReplyImplPrivate::_q_networkSessionConnected()
|
||||
{
|
||||
Q_Q(QNetworkReplyImpl);
|
||||
|
||||
if (manager.isNull())
|
||||
return;
|
||||
|
||||
QSharedPointer<QNetworkSession> session = manager->d_func()->getNetworkSession();
|
||||
if (!session)
|
||||
return;
|
||||
|
||||
if (session->state() != QNetworkSession::Connected)
|
||||
return;
|
||||
|
||||
switch (state) {
|
||||
case QNetworkReplyPrivate::Buffering:
|
||||
case QNetworkReplyPrivate::Working:
|
||||
case QNetworkReplyPrivate::Reconnecting:
|
||||
// Migrate existing downloads to new network connection.
|
||||
migrateBackend();
|
||||
break;
|
||||
case QNetworkReplyPrivate::WaitingForSession:
|
||||
// Start waiting requests.
|
||||
QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void QNetworkReplyImplPrivate::_q_networkSessionStateChanged(QNetworkSession::State sessionState)
|
||||
{
|
||||
if (sessionState == QNetworkSession::Disconnected
|
||||
&& state != Idle && state != Reconnecting) {
|
||||
error(QNetworkReplyImpl::NetworkSessionFailedError,
|
||||
QCoreApplication::translate("QNetworkReply", "Network session error."));
|
||||
finished();
|
||||
}
|
||||
}
|
||||
|
||||
void QNetworkReplyImplPrivate::_q_networkSessionFailed()
|
||||
{
|
||||
// Abort waiting and working replies.
|
||||
if (state == WaitingForSession || state == Working) {
|
||||
state = Working;
|
||||
QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession());
|
||||
QString errorStr;
|
||||
if (session)
|
||||
errorStr = session->errorString();
|
||||
else
|
||||
errorStr = QCoreApplication::translate("QNetworkReply", "Network session error.");
|
||||
error(QNetworkReplyImpl::NetworkSessionFailedError, errorStr);
|
||||
finished();
|
||||
}
|
||||
}
|
||||
|
||||
void QNetworkReplyImplPrivate::_q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies newPolicies)
|
||||
{
|
||||
if (backend->request().attribute(QNetworkRequest::BackgroundRequestAttribute).toBool()) {
|
||||
if (newPolicies & QNetworkSession::NoBackgroundTrafficPolicy) {
|
||||
// Abort waiting and working replies.
|
||||
if (state == WaitingForSession || state == Working) {
|
||||
state = Working;
|
||||
error(QNetworkReply::BackgroundRequestNotAllowedError,
|
||||
QCoreApplication::translate("QNetworkReply", "Background request not allowed."));
|
||||
finished();
|
||||
}
|
||||
// ### if backend->canResume(), then we could resume automatically, however no backend supports resuming
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void QNetworkReplyImplPrivate::setup(QNetworkAccessManager::Operation op, const QNetworkRequest &req,
|
||||
QIODevice *data)
|
||||
{
|
||||
@ -786,29 +661,6 @@ void QNetworkReplyImplPrivate::finished()
|
||||
if (preMigrationDownloaded != Q_INT64_C(-1))
|
||||
totalSize = totalSize.toLongLong() + preMigrationDownloaded;
|
||||
|
||||
if (!manager.isNull()) {
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
QSharedPointer<QNetworkSession> session (manager->d_func()->getNetworkSession());
|
||||
if (session && session->state() == QNetworkSession::Roaming &&
|
||||
state == Working && errorCode != QNetworkReply::OperationCanceledError) {
|
||||
// only content with a known size will fail with a temporary network failure error
|
||||
if (!totalSize.isNull()) {
|
||||
if (bytesDownloaded != totalSize) {
|
||||
if (migrateBackend()) {
|
||||
// either we are migrating or the request is finished/aborted
|
||||
if (state == Reconnecting || state == WaitingForSession) {
|
||||
resumeNotificationHandling();
|
||||
return; // exit early if we are migrating.
|
||||
}
|
||||
} else {
|
||||
error(QNetworkReply::TemporaryNetworkFailureError,
|
||||
QNetworkReply::tr("Temporary network failure."));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
resumeNotificationHandling();
|
||||
|
||||
state = Finished;
|
||||
|
@ -62,7 +62,6 @@
|
||||
#include "private/qringbuffer_p.h"
|
||||
#include "private/qbytedata_p.h"
|
||||
#include <QSharedPointer>
|
||||
#include <QtNetwork/QNetworkSession> // ### Qt6: Remove include
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -92,12 +91,6 @@ public:
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_copyReadChannelFinished())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingData())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingDataFinished())
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionConnected())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionFailed())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionStateChanged(QNetworkSession::State))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies))
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
protected:
|
||||
@ -124,12 +117,6 @@ public:
|
||||
void _q_copyReadChannelFinished();
|
||||
void _q_bufferOutgoingData();
|
||||
void _q_bufferOutgoingDataFinished();
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
void _q_networkSessionConnected();
|
||||
void _q_networkSessionFailed();
|
||||
void _q_networkSessionStateChanged(QNetworkSession::State);
|
||||
void _q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies);
|
||||
#endif
|
||||
|
||||
void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request,
|
||||
QIODevice *outgoingData);
|
||||
|
@ -241,10 +241,6 @@
|
||||
#include "qstringlist.h"
|
||||
#include "qurl.h"
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
#include <QtNetwork/QNetworkConfiguration>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QSocks5SocketEngineHandler;
|
||||
@ -1128,73 +1124,6 @@ QNetworkProxyQuery::QNetworkProxyQuery(quint16 bindPort, const QString &protocol
|
||||
d->type = queryType;
|
||||
}
|
||||
|
||||
#if !defined(QT_NO_BEARERMANAGEMENT) && QT_DEPRECATED_SINCE(5, 10)
|
||||
/*!
|
||||
\deprecated
|
||||
|
||||
Constructs a QNetworkProxyQuery with the URL \a requestUrl and
|
||||
sets the query type to \a queryType. The specified \a networkConfiguration
|
||||
parameter is ignored.
|
||||
|
||||
\sa protocolTag(), peerHostName(), peerPort(), networkConfiguration()
|
||||
*/
|
||||
QNetworkProxyQuery::QNetworkProxyQuery(const QNetworkConfiguration &networkConfiguration,
|
||||
const QUrl &requestUrl, QueryType queryType)
|
||||
{
|
||||
Q_UNUSED(networkConfiguration)
|
||||
d->remote = requestUrl;
|
||||
d->type = queryType;
|
||||
}
|
||||
|
||||
/*!
|
||||
\deprecated
|
||||
|
||||
Constructs a QNetworkProxyQuery of type \a queryType and sets the
|
||||
protocol tag to be \a protocolTag. This constructor is suitable
|
||||
for QNetworkProxyQuery::TcpSocket queries, because it sets the
|
||||
peer hostname to \a hostname and the peer's port number to \a
|
||||
port. The specified \a networkConfiguration parameter is ignored.
|
||||
|
||||
\sa networkConfiguration()
|
||||
*/
|
||||
QNetworkProxyQuery::QNetworkProxyQuery(const QNetworkConfiguration &networkConfiguration,
|
||||
const QString &hostname, int port,
|
||||
const QString &protocolTag,
|
||||
QueryType queryType)
|
||||
{
|
||||
Q_UNUSED(networkConfiguration);
|
||||
d->remote.setScheme(protocolTag);
|
||||
d->remote.setHost(hostname);
|
||||
d->remote.setPort(port);
|
||||
d->type = queryType;
|
||||
}
|
||||
|
||||
/*!
|
||||
\deprecated
|
||||
|
||||
Constructs a QNetworkProxyQuery of type \a queryType and sets the
|
||||
protocol tag to be \a protocolTag. This constructor is suitable
|
||||
for QNetworkProxyQuery::TcpSocket queries because it sets the
|
||||
local port number to \a bindPort. The specified \a networkConfiguration
|
||||
parameter is ignored.
|
||||
|
||||
Note that \a bindPort is of type quint16 to indicate the exact
|
||||
port number that is requested. The value of -1 (unknown) is not
|
||||
allowed in this context.
|
||||
|
||||
\sa localPort(), networkConfiguration()
|
||||
*/
|
||||
QNetworkProxyQuery::QNetworkProxyQuery(const QNetworkConfiguration &networkConfiguration,
|
||||
quint16 bindPort, const QString &protocolTag,
|
||||
QueryType queryType)
|
||||
{
|
||||
Q_UNUSED(networkConfiguration);
|
||||
d->remote.setScheme(protocolTag);
|
||||
d->localPort = bindPort;
|
||||
d->type = queryType;
|
||||
}
|
||||
#endif // !defined(QT_NO_BEARERMANAGEMENT) && QT_DEPRECATED_SINCE(5, 10)
|
||||
|
||||
/*!
|
||||
Constructs a QNetworkProxyQuery object that is a copy of \a other.
|
||||
*/
|
||||
@ -1417,33 +1346,6 @@ void QNetworkProxyQuery::setUrl(const QUrl &url)
|
||||
d->remote = url;
|
||||
}
|
||||
|
||||
#if !defined(QT_NO_BEARERMANAGEMENT) && QT_DEPRECATED_SINCE(5, 10)
|
||||
/*!
|
||||
\deprecated
|
||||
|
||||
Returns QNetworkConfiguration().
|
||||
|
||||
\sa setNetworkConfiguration()
|
||||
*/
|
||||
QNetworkConfiguration QNetworkProxyQuery::networkConfiguration() const
|
||||
{
|
||||
return QNetworkConfiguration();
|
||||
}
|
||||
|
||||
/*!
|
||||
\deprecated
|
||||
|
||||
This function does nothing. The specified \a networkConfiguration parameter
|
||||
is ignored.
|
||||
|
||||
\sa networkConfiguration()
|
||||
*/
|
||||
void QNetworkProxyQuery::setNetworkConfiguration(const QNetworkConfiguration &networkConfiguration)
|
||||
{
|
||||
Q_UNUSED(networkConfiguration);
|
||||
}
|
||||
#endif // !defined(QT_NO_BEARERMANAGEMENT) && QT_DEPRECATED_SINCE(5, 10)
|
||||
|
||||
/*!
|
||||
\class QNetworkProxyFactory
|
||||
\brief The QNetworkProxyFactory class provides fine-grained proxy selection.
|
||||
|
@ -75,22 +75,6 @@ public:
|
||||
QueryType queryType = TcpSocket);
|
||||
explicit QNetworkProxyQuery(quint16 bindPort, const QString &protocolTag = QString(),
|
||||
QueryType queryType = TcpServer);
|
||||
#if !defined(QT_NO_BEARERMANAGEMENT) && QT_DEPRECATED_SINCE(5, 10)
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
Q_DECL_DEPRECATED_X("QNetworkConfiguration support in QNetworkProxy is deprecated")
|
||||
QNetworkProxyQuery(const QNetworkConfiguration &networkConfiguration,
|
||||
const QUrl &requestUrl, QueryType queryType = UrlRequest);
|
||||
Q_DECL_DEPRECATED_X("QNetworkConfiguration support in QNetworkProxy is deprecated")
|
||||
QNetworkProxyQuery(const QNetworkConfiguration &networkConfiguration,
|
||||
const QString &hostname, int port, const QString &protocolTag = QString(),
|
||||
QueryType queryType = TcpSocket);
|
||||
Q_DECL_DEPRECATED_X("QNetworkConfiguration support in QNetworkProxy is deprecated")
|
||||
QNetworkProxyQuery(const QNetworkConfiguration &networkConfiguration,
|
||||
quint16 bindPort, const QString &protocolTag = QString(),
|
||||
QueryType queryType = TcpServer);
|
||||
QT_WARNING_POP
|
||||
#endif
|
||||
QNetworkProxyQuery(const QNetworkProxyQuery &other);
|
||||
QNetworkProxyQuery &operator=(QNetworkProxyQuery &&other) noexcept { swap(other); return *this; }
|
||||
QNetworkProxyQuery &operator=(const QNetworkProxyQuery &other);
|
||||
@ -120,16 +104,6 @@ QT_WARNING_POP
|
||||
QUrl url() const;
|
||||
void setUrl(const QUrl &url);
|
||||
|
||||
#if !defined(QT_NO_BEARERMANAGEMENT) && QT_DEPRECATED_SINCE(5, 10)
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
Q_DECL_DEPRECATED_X("QNetworkConfiguration support in QNetworkProxy is deprecated")
|
||||
QNetworkConfiguration networkConfiguration() const;
|
||||
Q_DECL_DEPRECATED_X("QNetworkConfiguration support in QNetworkProxy is deprecated")
|
||||
void setNetworkConfiguration(const QNetworkConfiguration &networkConfiguration);
|
||||
QT_WARNING_POP
|
||||
#endif
|
||||
|
||||
private:
|
||||
QSharedDataPointer<QNetworkProxyQueryPrivate> d;
|
||||
};
|
||||
|
@ -475,10 +475,6 @@
|
||||
#include "qabstractsocket_p.h"
|
||||
|
||||
#include "private/qhostinfo_p.h"
|
||||
#if QT_CONFIG(bearermanagement) // ### Qt6: Remove section
|
||||
#include "private/qnetworksession_p.h"
|
||||
#endif
|
||||
#include "private/qnetworkconfiguration_p.h" // ### Qt6: Remove include
|
||||
|
||||
#include <qabstracteventdispatcher.h>
|
||||
#include <qhostaddress.h>
|
||||
@ -514,6 +510,8 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
static const int DefaultConnectTimeout = 30000;
|
||||
|
||||
#if defined QABSTRACTSOCKET_DEBUG
|
||||
QT_BEGIN_INCLUDE_NAMESPACE
|
||||
#include <qstring.h>
|
||||
@ -657,10 +655,6 @@ bool QAbstractSocketPrivate::initSocketLayer(QAbstractSocket::NetworkLayerProtoc
|
||||
QAbstractSocket::tr("Operation on socket is not supported"));
|
||||
return false;
|
||||
}
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
//copy network session down to the socket engine (if it has been set)
|
||||
socketEngine->setProperty("_q_networksession", q->property("_q_networksession"));
|
||||
#endif
|
||||
if (!socketEngine->initialize(q->socketType(), protocol)) {
|
||||
#if defined (QABSTRACTSOCKET_DEBUG)
|
||||
qDebug("QAbstractSocketPrivate::initSocketLayer(%s, %s) failed (%s)",
|
||||
@ -1159,14 +1153,7 @@ void QAbstractSocketPrivate::_q_connectToNextAddress()
|
||||
q, SLOT(_q_abortConnectionAttempt()),
|
||||
Qt::DirectConnection);
|
||||
}
|
||||
int connectTimeout = QNetworkConfigurationPrivate::DefaultTimeout;
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
QSharedPointer<QNetworkSession> networkSession = qvariant_cast< QSharedPointer<QNetworkSession> >(q->property("_q_networksession"));
|
||||
if (networkSession) {
|
||||
QNetworkConfiguration networkConfiguration = networkSession->configuration();
|
||||
connectTimeout = networkConfiguration.connectTimeout();
|
||||
}
|
||||
#endif
|
||||
int connectTimeout = DefaultConnectTimeout;
|
||||
connectTimer->start(connectTimeout);
|
||||
}
|
||||
|
||||
@ -1953,10 +1940,6 @@ bool QAbstractSocket::setSocketDescriptor(qintptr socketDescriptor, SocketState
|
||||
d->setError(UnsupportedSocketOperationError, tr("Operation on socket is not supported"));
|
||||
return false;
|
||||
}
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
//copy network session down to the socket engine (if it has been set)
|
||||
d->socketEngine->setProperty("_q_networksession", property("_q_networksession"));
|
||||
#endif
|
||||
bool result = d->socketEngine->initialize(socketDescriptor, socketState);
|
||||
if (!result) {
|
||||
d->setError(d->socketEngine->error(), d->socketEngine->errorString());
|
||||
@ -2146,10 +2129,6 @@ bool QAbstractSocket::waitForConnected(int msecs)
|
||||
QElapsedTimer stopWatch;
|
||||
stopWatch.start();
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
QSharedPointer<QNetworkSession> networkSession = qvariant_cast< QSharedPointer<QNetworkSession> >(property("_q_networksession"));
|
||||
#endif
|
||||
|
||||
if (d->state == HostLookupState) {
|
||||
#if defined (QABSTRACTSOCKET_DEBUG)
|
||||
qDebug("QAbstractSocket::waitForConnected(%i) doing host name lookup", msecs);
|
||||
@ -2168,13 +2147,7 @@ bool QAbstractSocket::waitForConnected(int msecs)
|
||||
if (state() == UnconnectedState)
|
||||
return false; // connect not im progress anymore!
|
||||
|
||||
int connectTimeout = QNetworkConfigurationPrivate::DefaultTimeout;
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
if (networkSession) {
|
||||
QNetworkConfiguration networkConfiguration = networkSession->configuration();
|
||||
connectTimeout = networkConfiguration.connectTimeout();
|
||||
}
|
||||
#endif
|
||||
int connectTimeout = DefaultConnectTimeout;
|
||||
bool timedOut = true;
|
||||
#if defined (QABSTRACTSOCKET_DEBUG)
|
||||
int attempt = 1;
|
||||
|
@ -72,9 +72,6 @@ bool QHttpSocketEngine::initialize(QAbstractSocket::SocketType type, QAbstractSo
|
||||
setSocketType(type);
|
||||
d->socket = new QTcpSocket(this);
|
||||
d->reply = new QHttpNetworkReply(QUrl(), this);
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
d->socket->setProperty("_q_networkSession", property("_q_networkSession"));
|
||||
#endif
|
||||
|
||||
// Explicitly disable proxying on the proxy socket itself to avoid
|
||||
// unwanted recursion.
|
||||
|
@ -535,9 +535,6 @@ void QSocks5SocketEnginePrivate::initialize(Socks5Mode socks5Mode)
|
||||
udpData = new QSocks5UdpAssociateData;
|
||||
data = udpData;
|
||||
udpData->udpSocket = new QUdpSocket(q);
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
udpData->udpSocket->setProperty("_q_networksession", q->property("_q_networksession"));
|
||||
#endif
|
||||
udpData->udpSocket->setProxy(QNetworkProxy::NoProxy);
|
||||
QObject::connect(udpData->udpSocket, SIGNAL(readyRead()),
|
||||
q, SLOT(_q_udpSocketReadNotification()),
|
||||
@ -549,9 +546,6 @@ void QSocks5SocketEnginePrivate::initialize(Socks5Mode socks5Mode)
|
||||
}
|
||||
|
||||
data->controlSocket = new QTcpSocket(q);
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
data->controlSocket->setProperty("_q_networksession", q->property("_q_networksession"));
|
||||
#endif
|
||||
data->controlSocket->setProxy(QNetworkProxy::NoProxy);
|
||||
QObject::connect(data->controlSocket, SIGNAL(connected()), q, SLOT(_q_controlSocketConnected()),
|
||||
Qt::DirectConnection);
|
||||
|
@ -314,10 +314,6 @@ bool QTcpServer::listen(const QHostAddress &address, quint16 port)
|
||||
d->serverSocketErrorString = tr("Operation on socket is not supported");
|
||||
return false;
|
||||
}
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
//copy network session down to the socket engine (if it has been set)
|
||||
d->socketEngine->setProperty("_q_networksession", property("_q_networksession"));
|
||||
#endif
|
||||
if (!d->socketEngine->initialize(d->socketType, proto)) {
|
||||
d->serverSocketError = d->socketEngine->error();
|
||||
d->serverSocketErrorString = d->socketEngine->errorString();
|
||||
@ -436,10 +432,6 @@ bool QTcpServer::setSocketDescriptor(qintptr socketDescriptor)
|
||||
d->serverSocketErrorString = tr("Operation on socket is not supported");
|
||||
return false;
|
||||
}
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
//copy network session down to the socket engine (if it has been set)
|
||||
d->socketEngine->setProperty("_q_networksession", property("_q_networksession"));
|
||||
#endif
|
||||
if (!d->socketEngine->initialize(socketDescriptor, QAbstractSocket::ListeningState)) {
|
||||
d->serverSocketError = d->socketEngine->error();
|
||||
d->serverSocketErrorString = d->socketEngine->errorString();
|
||||
|
@ -2586,10 +2586,6 @@ void QSslSocketPrivate::createPlainSocket(QIODevice::OpenMode openMode)
|
||||
q->setPeerName(QString());
|
||||
|
||||
plainSocket = new QTcpSocket(q);
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
//copy network session down to the plain socket (if it has been set)
|
||||
plainSocket->setProperty("_q_networksession", q->property("_q_networksession"));
|
||||
#endif
|
||||
q->connect(plainSocket, SIGNAL(connected()),
|
||||
q, SLOT(_q_connectedSlot()),
|
||||
Qt::DirectConnection);
|
||||
|
@ -30,16 +30,9 @@
|
||||
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
#include <QtNetwork/QNetworkConfigurationManager>
|
||||
#endif
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
Q_DECLARE_METATYPE(QNetworkAccessManager::NetworkAccessibility)
|
||||
#endif
|
||||
|
||||
class tst_QNetworkAccessManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -48,7 +41,6 @@ public:
|
||||
tst_QNetworkAccessManager();
|
||||
|
||||
private slots:
|
||||
void networkAccessible();
|
||||
void alwaysCacheRequest();
|
||||
};
|
||||
|
||||
@ -56,77 +48,6 @@ tst_QNetworkAccessManager::tst_QNetworkAccessManager()
|
||||
{
|
||||
}
|
||||
|
||||
void tst_QNetworkAccessManager::networkAccessible()
|
||||
{
|
||||
#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
|
||||
QNetworkAccessManager manager;
|
||||
|
||||
qRegisterMetaType<QNetworkAccessManager::NetworkAccessibility>("QNetworkAccessManager::NetworkAccessibility");
|
||||
|
||||
QSignalSpy spy(&manager,
|
||||
SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)));
|
||||
|
||||
// if there is no session, we cannot know in which state we are in
|
||||
QNetworkAccessManager::NetworkAccessibility initialAccessibility =
|
||||
manager.networkAccessible();
|
||||
|
||||
if (initialAccessibility == QNetworkAccessManager::UnknownAccessibility)
|
||||
QSKIP("Unknown accessibility", SkipAll);
|
||||
|
||||
QCOMPARE(manager.networkAccessible(), initialAccessibility);
|
||||
|
||||
manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible);
|
||||
|
||||
int expectedCount = (initialAccessibility == QNetworkAccessManager::Accessible) ? 1 : 0;
|
||||
QCOMPARE(spy.count(), expectedCount);
|
||||
if (expectedCount > 0)
|
||||
QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
|
||||
QNetworkAccessManager::NotAccessible);
|
||||
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
|
||||
|
||||
// When network is not accessible, all requests fail
|
||||
QNetworkReply *reply = manager.get(QNetworkRequest(QUrl("http://www.example.org")));
|
||||
QSignalSpy finishedSpy(reply, &QNetworkReply::finished);
|
||||
QSignalSpy errorSpy(reply, &QNetworkReply::errorOccurred);
|
||||
QVERIFY(finishedSpy.wait());
|
||||
QCOMPARE(reply->isFinished(), true);
|
||||
QCOMPARE(reply->errorString(), QStringLiteral("Network access is disabled."));
|
||||
QCOMPARE(errorSpy.count(), 1);
|
||||
|
||||
manager.setNetworkAccessible(QNetworkAccessManager::Accessible);
|
||||
|
||||
QCOMPARE(spy.count(), expectedCount);
|
||||
if (expectedCount > 0)
|
||||
QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
|
||||
initialAccessibility);
|
||||
QCOMPARE(manager.networkAccessible(), initialAccessibility);
|
||||
|
||||
QNetworkConfigurationManager configManager;
|
||||
QNetworkConfiguration defaultConfig = configManager.defaultConfiguration();
|
||||
if (defaultConfig.isValid()) {
|
||||
manager.setConfiguration(defaultConfig);
|
||||
|
||||
QCOMPARE(spy.count(), 0);
|
||||
|
||||
if (defaultConfig.state().testFlag(QNetworkConfiguration::Active))
|
||||
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::Accessible);
|
||||
else
|
||||
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
|
||||
|
||||
manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible);
|
||||
|
||||
if (defaultConfig.state().testFlag(QNetworkConfiguration::Active)) {
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QCOMPARE(QNetworkAccessManager::NetworkAccessibility(spy.takeFirst().at(0).toInt()),
|
||||
QNetworkAccessManager::NotAccessible);
|
||||
} else {
|
||||
QCOMPARE(spy.count(), 0);
|
||||
}
|
||||
}
|
||||
QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QNetworkAccessManager::alwaysCacheRequest()
|
||||
{
|
||||
QNetworkAccessManager manager;
|
||||
|
@ -66,12 +66,6 @@
|
||||
#include <QtNetwork/private/qsslconfiguration_p.h>
|
||||
#endif
|
||||
#endif
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
#include <QtNetwork/qnetworkconfigmanager.h>
|
||||
#include <QtNetwork/qnetworkconfiguration.h>
|
||||
#include <QtNetwork/qnetworksession.h>
|
||||
#include <QtNetwork/private/qnetworksession_p.h>
|
||||
#endif
|
||||
#ifdef QT_BUILD_INTERNAL
|
||||
#include <QtNetwork/private/qnetworkreplyimpl_p.h> // implicitly included by qnetworkaccessmanager_p.h currently, but don't rely on that being true forever
|
||||
#include <QtNetwork/private/qnetworkaccessmanager_p.h>
|
||||
@ -161,11 +155,6 @@ class tst_QNetworkReply: public QObject
|
||||
QList<QSslError> storedExpectedSslErrors;
|
||||
static const QString certsFilePath;
|
||||
#endif
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
QNetworkConfigurationManager *netConfMan;
|
||||
QNetworkConfiguration networkConfiguration;
|
||||
QScopedPointer<QNetworkSession> networkSession;
|
||||
#endif
|
||||
|
||||
using QObject::connect;
|
||||
static bool connect(const QNetworkReplyPtr &ptr, const char *signal, const QObject *receiver, const char *slot, Qt::ConnectionType ct = Qt::AutoConnection)
|
||||
@ -481,15 +470,6 @@ private Q_SLOTS:
|
||||
|
||||
void emitErrorForAllReplies(); // QTBUG-36890
|
||||
|
||||
#ifdef QT_BUILD_INTERNAL
|
||||
void backgroundRequest_data();
|
||||
void backgroundRequest();
|
||||
void backgroundRequestInterruption_data();
|
||||
void backgroundRequestInterruption();
|
||||
void backgroundRequestConnectInBackground_data();
|
||||
void backgroundRequestConnectInBackground();
|
||||
#endif
|
||||
|
||||
void putWithRateLimiting();
|
||||
|
||||
void ioHttpSingleRedirect();
|
||||
@ -1576,15 +1556,6 @@ void tst_QNetworkReply::initTestCase()
|
||||
#ifndef QT_NO_SSL
|
||||
QSslConfiguration::defaultConfiguration().caCertificates(); //preload certificates
|
||||
#endif
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
netConfMan = new QNetworkConfigurationManager(this);
|
||||
networkConfiguration = netConfMan->defaultConfiguration();
|
||||
networkSession.reset(new QNetworkSession(networkConfiguration));
|
||||
if (!networkSession->isOpen()) {
|
||||
networkSession->open();
|
||||
QVERIFY(networkSession->waitForOpened(30000));
|
||||
}
|
||||
#endif
|
||||
|
||||
echoProcessDir = QFINDTESTDATA("echo");
|
||||
QVERIFY2(!echoProcessDir.isEmpty(), qPrintable(
|
||||
@ -1599,11 +1570,6 @@ void tst_QNetworkReply::cleanupTestCase()
|
||||
if (!wronlyFileName.isNull())
|
||||
QFile::remove(wronlyFileName);
|
||||
#endif
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
if (networkSession && networkSession->isOpen()) {
|
||||
networkSession->close();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QNetworkReply::cleanupTestData()
|
||||
@ -5931,11 +5897,6 @@ void tst_QNetworkReply::httpProxyCommands()
|
||||
QNetworkRequest request(url);
|
||||
request.setRawHeader("User-Agent", "QNetworkReplyAutoTest/1.0");
|
||||
QNetworkReplyPtr reply(manager.get(request));
|
||||
//clearing the proxy here causes the test to fail.
|
||||
//the proxy isn't used until after the bearer has been started
|
||||
//which is correct in general, because system proxy isn't known until that time.
|
||||
//removing this line is safe, as the proxy is also reset by the cleanup() function
|
||||
//manager.setProxy(QNetworkProxy());
|
||||
|
||||
// wait for the finished signal
|
||||
QVERIFY(waitForFinish(reply) != Timeout);
|
||||
@ -7028,38 +6989,7 @@ void tst_QNetworkReply::getFromUnreachableIp()
|
||||
// NOERROR; so socket engine starts a timer (30 s.) and waits for a timeout/
|
||||
// error/success. Unfortunately, the test itself is waiting only for 5 s.
|
||||
// So we have to adjust the connection timeout or skip the test completely
|
||||
// if the 'bearermanagement' feature is not available.
|
||||
#if QT_CONFIG(bearermanagement)
|
||||
class ConfigurationGuard
|
||||
{
|
||||
public:
|
||||
explicit ConfigurationGuard(QNetworkAccessManager *m)
|
||||
: manager(m)
|
||||
{
|
||||
Q_ASSERT(m);
|
||||
auto conf = manager->configuration();
|
||||
previousTimeout = conf.connectTimeout();
|
||||
conf.setConnectTimeout(1500);
|
||||
manager->setConfiguration(conf);
|
||||
}
|
||||
~ConfigurationGuard()
|
||||
{
|
||||
Q_ASSERT(manager);
|
||||
auto conf = manager->configuration();
|
||||
conf.setConnectTimeout(previousTimeout);
|
||||
manager->setConfiguration(conf);
|
||||
}
|
||||
private:
|
||||
QNetworkAccessManager *manager = nullptr;
|
||||
int previousTimeout = 0;
|
||||
|
||||
Q_DISABLE_COPY(ConfigurationGuard)
|
||||
};
|
||||
|
||||
const ConfigurationGuard restorer(&manager);
|
||||
#else // bearermanagement
|
||||
QSKIP("This test is non-deterministic on Windows x86");
|
||||
#endif // !bearermanagement
|
||||
#endif // Q_OS_WIN
|
||||
|
||||
QNetworkRequest request(QUrl("http://255.255.255.255/42/23/narf/narf/narf"));
|
||||
@ -8136,233 +8066,6 @@ void tst_QNetworkReply::emitErrorForAllReplies() // QTBUG-36890
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef QT_BUILD_INTERNAL
|
||||
void tst_QNetworkReply::backgroundRequest_data()
|
||||
{
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
QTest::addColumn<QUrl>("url");
|
||||
QTest::addColumn<bool>("background");
|
||||
QTest::addColumn<int>("policy");
|
||||
QTest::addColumn<QNetworkReply::NetworkError>("error");
|
||||
|
||||
QUrl httpurl("http://" + QtNetworkSettings::httpServerName());
|
||||
QUrl httpsurl("https://" + QtNetworkSettings::httpServerName());
|
||||
#if QT_CONFIG(ftp)
|
||||
QUrl ftpurl("ftp://" + QtNetworkSettings::ftpServerName() + "/qtest/rfc3252.txt");
|
||||
#endif
|
||||
|
||||
QTest::newRow("http, fg, normal") << httpurl << false << (int)QNetworkSession::NoPolicy << QNetworkReply::NoError;
|
||||
QTest::newRow("http, bg, normal") << httpurl << true << (int)QNetworkSession::NoPolicy << QNetworkReply::NoError;
|
||||
QTest::newRow("http, fg, nobg") << httpurl << false << (int)QNetworkSession::NoBackgroundTrafficPolicy << QNetworkReply::NoError;
|
||||
QTest::newRow("http, bg, nobg") << httpurl << true << (int)QNetworkSession::NoBackgroundTrafficPolicy << QNetworkReply::BackgroundRequestNotAllowedError;
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
QTest::newRow("https, fg, normal") << httpsurl << false << (int)QNetworkSession::NoPolicy << QNetworkReply::NoError;
|
||||
QTest::newRow("https, bg, normal") << httpsurl << true << (int)QNetworkSession::NoPolicy << QNetworkReply::NoError;
|
||||
QTest::newRow("https, fg, nobg") << httpsurl << false << (int)QNetworkSession::NoBackgroundTrafficPolicy << QNetworkReply::NoError;
|
||||
QTest::newRow("https, bg, nobg") << httpsurl << true << (int)QNetworkSession::NoBackgroundTrafficPolicy << QNetworkReply::BackgroundRequestNotAllowedError;
|
||||
#endif
|
||||
|
||||
#if QT_CONFIG(ftp)
|
||||
QTest::newRow("ftp, fg, normal") << ftpurl << false << (int)QNetworkSession::NoPolicy << QNetworkReply::NoError;
|
||||
QTest::newRow("ftp, bg, normal") << ftpurl << true << (int)QNetworkSession::NoPolicy << QNetworkReply::NoError;
|
||||
QTest::newRow("ftp, fg, nobg") << ftpurl << false << (int)QNetworkSession::NoBackgroundTrafficPolicy << QNetworkReply::NoError;
|
||||
QTest::newRow("ftp, bg, nobg") << ftpurl << true << (int)QNetworkSession::NoBackgroundTrafficPolicy << QNetworkReply::BackgroundRequestNotAllowedError;
|
||||
#endif
|
||||
#endif // !QT_NO_BEARERMANAGEMENT
|
||||
}
|
||||
#endif
|
||||
|
||||
//test purpose: background requests can't be started when not allowed
|
||||
#ifdef QT_BUILD_INTERNAL
|
||||
void tst_QNetworkReply::backgroundRequest()
|
||||
{
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
QFETCH(QUrl, url);
|
||||
QFETCH(bool, background);
|
||||
QFETCH(int, policy);
|
||||
QFETCH(QNetworkReply::NetworkError, error);
|
||||
|
||||
QNetworkRequest request(url);
|
||||
|
||||
if (background)
|
||||
request.setAttribute(QNetworkRequest::BackgroundRequestAttribute, QVariant::fromValue(true));
|
||||
|
||||
//this preconstructs the session so we can change policies in advance
|
||||
manager.setConfiguration(networkConfiguration);
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
connect(&manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
|
||||
SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
|
||||
#endif
|
||||
|
||||
const QWeakPointer<const QNetworkSession> sessionWeakPtr = QNetworkAccessManagerPrivate::getNetworkSession(&manager);
|
||||
QVERIFY(!sessionWeakPtr.isNull());
|
||||
auto session = const_cast<QNetworkSession *>(sessionWeakPtr.toStrongRef().data());
|
||||
QNetworkSession::UsagePolicies original = session->usagePolicies();
|
||||
QNetworkSessionPrivate::setUsagePolicies(*session, QNetworkSession::UsagePolicies(policy));
|
||||
|
||||
QNetworkReplyPtr reply(manager.get(request));
|
||||
|
||||
QVERIFY(waitForFinish(reply) != Timeout);
|
||||
if (session)
|
||||
QNetworkSessionPrivate::setUsagePolicies(*session, original);
|
||||
|
||||
QVERIFY(reply->isFinished());
|
||||
QCOMPARE(reply->error(), error);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef QT_BUILD_INTERNAL
|
||||
void tst_QNetworkReply::backgroundRequestInterruption_data()
|
||||
{
|
||||
QTest::addColumn<QUrl>("url");
|
||||
QTest::addColumn<bool>("background");
|
||||
QTest::addColumn<QNetworkReply::NetworkError>("error");
|
||||
|
||||
QUrl httpurl("http://" + QtNetworkSettings::httpServerName() + "/qtest/mediumfile");
|
||||
QUrl httpsurl("https://" + QtNetworkSettings::httpServerName() + "/qtest/mediumfile");
|
||||
#if QT_CONFIG(ftp)
|
||||
QUrl ftpurl("ftp://" + QtNetworkSettings::ftpServerName() + "/qtest/bigfile");
|
||||
#endif
|
||||
|
||||
QTest::newRow("http, fg, nobg") << httpurl << false << QNetworkReply::NoError;
|
||||
QTest::newRow("http, bg, nobg") << httpurl << true << QNetworkReply::BackgroundRequestNotAllowedError;
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
QTest::newRow("https, fg, nobg") << httpsurl << false << QNetworkReply::NoError;
|
||||
QTest::newRow("https, bg, nobg") << httpsurl << true << QNetworkReply::BackgroundRequestNotAllowedError;
|
||||
#endif
|
||||
|
||||
#if QT_CONFIG(ftp)
|
||||
QTest::newRow("ftp, fg, nobg") << ftpurl << false << QNetworkReply::NoError;
|
||||
QTest::newRow("ftp, bg, nobg") << ftpurl << true << QNetworkReply::BackgroundRequestNotAllowedError;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
//test purpose: background requests in progress are aborted when policy changes to disallow them
|
||||
#ifdef QT_BUILD_INTERNAL
|
||||
void tst_QNetworkReply::backgroundRequestInterruption()
|
||||
{
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
if (QNetworkStatusMonitor::isEnabled() && QByteArray(QTest::currentDataTag()).startsWith("http"))
|
||||
QSKIP("This test (currently) doesn't make any sense when QNetworkStatusMonitor is enabled");
|
||||
|
||||
QFETCH(QUrl, url);
|
||||
QFETCH(bool, background);
|
||||
QFETCH(QNetworkReply::NetworkError, error);
|
||||
|
||||
QNetworkRequest request(url);
|
||||
|
||||
if (background)
|
||||
request.setAttribute(QNetworkRequest::BackgroundRequestAttribute, QVariant::fromValue(true));
|
||||
|
||||
//this preconstructs the session so we can change policies in advance
|
||||
manager.setConfiguration(networkConfiguration);
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
connect(&manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
|
||||
SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
|
||||
#endif
|
||||
|
||||
const QWeakPointer<const QNetworkSession> sessionWeakPtr = QNetworkAccessManagerPrivate::getNetworkSession(&manager);
|
||||
QVERIFY(!sessionWeakPtr.isNull());
|
||||
auto session = const_cast<QNetworkSession *>(sessionWeakPtr.toStrongRef().data());
|
||||
QNetworkSession::UsagePolicies original = session->usagePolicies();
|
||||
QNetworkSessionPrivate::setUsagePolicies(*session, QNetworkSession::NoPolicy);
|
||||
|
||||
request.setAttribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute, 8192);
|
||||
QNetworkReplyPtr reply(manager.get(request));
|
||||
reply->setReadBufferSize(1024);
|
||||
|
||||
QSignalSpy spy(reply.data(), SIGNAL(readyRead()));
|
||||
QTRY_VERIFY(spy.count() > 0);
|
||||
|
||||
QNetworkSessionPrivate::setUsagePolicies(*session, QNetworkSession::NoBackgroundTrafficPolicy);
|
||||
|
||||
// After we have changed the policy we can download at full speed.
|
||||
reply->setReadBufferSize(0);
|
||||
|
||||
QVERIFY(waitForFinish(reply) != Timeout);
|
||||
if (session)
|
||||
QNetworkSessionPrivate::setUsagePolicies(*session, original);
|
||||
|
||||
QVERIFY(reply->isFinished());
|
||||
QCOMPARE(reply->error(), error);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef QT_BUILD_INTERNAL
|
||||
void tst_QNetworkReply::backgroundRequestConnectInBackground_data()
|
||||
{
|
||||
QTest::addColumn<QUrl>("url");
|
||||
QTest::addColumn<bool>("background");
|
||||
|
||||
QUrl httpurl("http://" + QtNetworkSettings::httpServerName());
|
||||
#if QT_CONFIG(ftp)
|
||||
QUrl ftpurl("ftp://" + QtNetworkSettings::ftpServerName() + "/qtest/rfc3252.txt");
|
||||
#endif
|
||||
|
||||
QTest::newRow("http, fg") << httpurl << false;
|
||||
QTest::newRow("http, bg") << httpurl << true;
|
||||
|
||||
#if QT_CONFIG(ftp)
|
||||
QTest::newRow("ftp, fg") << ftpurl << false;
|
||||
QTest::newRow("ftp, bg") << ftpurl << true;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
//test purpose: check that backgroundness is propagated to the network session
|
||||
#ifdef QT_BUILD_INTERNAL
|
||||
void tst_QNetworkReply::backgroundRequestConnectInBackground()
|
||||
{
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
QFETCH(QUrl, url);
|
||||
QFETCH(bool, background);
|
||||
|
||||
QNetworkRequest request(url);
|
||||
|
||||
if (background)
|
||||
request.setAttribute(QNetworkRequest::BackgroundRequestAttribute, QVariant::fromValue(true));
|
||||
|
||||
QWeakPointer<const QNetworkSession> session = QNetworkAccessManagerPrivate::getNetworkSession(&manager);
|
||||
//force QNAM to reopen the session.
|
||||
if (session && session.toStrongRef().data()->isOpen()) {
|
||||
const_cast<QNetworkSession *>(session.toStrongRef().data())->close();
|
||||
QCoreApplication::processEvents(); //let signals propagate inside QNAM
|
||||
}
|
||||
|
||||
//this preconstructs the session so we can change policies in advance
|
||||
manager.setConfiguration(networkConfiguration);
|
||||
|
||||
session = QNetworkAccessManagerPrivate::getNetworkSession(&manager);
|
||||
QVERIFY(session);
|
||||
QNetworkSession::UsagePolicies original = session.toStrongRef().data()->usagePolicies();
|
||||
QNetworkSessionPrivate::setUsagePolicies(*const_cast<QNetworkSession *>(session.toStrongRef().data()), QNetworkSession::NoPolicy);
|
||||
|
||||
QNetworkReplyPtr reply(manager.get(request));
|
||||
|
||||
QVERIFY(waitForFinish(reply) != Timeout);
|
||||
session = QNetworkAccessManagerPrivate::getNetworkSession(&manager);
|
||||
if (session) {
|
||||
QVariant cib = session.toStrongRef().data()->sessionProperty(QStringLiteral("ConnectInBackground"));
|
||||
if (!cib.isValid())
|
||||
QSKIP("inconclusive - ConnectInBackground session property not supported by the bearer plugin");
|
||||
QCOMPARE(cib.toBool(), background);
|
||||
QNetworkSessionPrivate::setUsagePolicies(*const_cast<QNetworkSession *>(session.toStrongRef().data()), original);
|
||||
} else {
|
||||
QSKIP("inconclusive - network session has been destroyed");
|
||||
}
|
||||
|
||||
QVERIFY(reply->isFinished());
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
class RateLimitedUploadDevice : public QIODevice
|
||||
{
|
||||
Q_OBJECT
|
||||
|
Loading…
x
Reference in New Issue
Block a user