summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2011-04-18 15:23:33 +0100
committerMarkus Goetz <Markus.Goetz@nokia.com>2011-05-09 13:14:46 +0200
commit1ad3814a56ded1852efb3389edd03866699412f6 (patch)
treeea720a6d5735867fbf6b3baf0447825e1ae0da05 /src/network
parentf0f55cd59f72887e4d80ef5ba752400777458be0 (diff)
Enable per network configuration proxy settings in QNetworkAccessManager
Delayed the resolving of the proxy until the backend is being started. This is because the proxy settings are not known until after QNetworkAccessManager has brought the network online using QNetworkSession. On Nokia's symbian3 phones, the default network configuration is a service network containing a list of access points in priority order. For a typical user, this will include one or more WLAN networks and a cellular network - each of which can have different proxy settings. Task-number: QTBUG-18618 Reviewed-by: Peter Hartmann
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qnetworkaccessbackend.cpp76
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp4
2 files changed, 53 insertions, 27 deletions
diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp
index 8a53d2dfa6..a0042f436b 100644
--- a/src/network/access/qnetworkaccessbackend.cpp
+++ b/src/network/access/qnetworkaccessbackend.cpp
@@ -41,6 +41,7 @@
#include "qnetworkaccessbackend_p.h"
#include "qnetworkaccessmanager_p.h"
+#include "qnetworkconfigmanager.h"
#include "qnetworkrequest.h"
#include "qnetworkreply.h"
#include "qnetworkreply_p.h"
@@ -343,8 +344,6 @@ void QNetworkAccessBackend::sslErrors(const QList<QSslError> &errors)
#endif
}
-#ifndef QT_NO_BEARERMANAGEMENT
-
/*!
Starts the backend. Returns true if the backend is started. Returns false if the backend
could not be started due to an unopened or roaming session. The caller should recall this
@@ -352,31 +351,62 @@ void QNetworkAccessBackend::sslErrors(const QList<QSslError> &errors)
*/
bool QNetworkAccessBackend::start()
{
- if (!manager->networkSession) {
- open();
- return true;
- }
-
- // This is not ideal.
- const QString host = reply->url.host();
- if (host == QLatin1String("localhost") ||
- QHostAddress(host) == QHostAddress::LocalHost ||
- QHostAddress(host) == QHostAddress::LocalHostIPv6) {
- // Don't need an open session for localhost access.
- open();
- return true;
+#ifndef QT_NO_BEARERMANAGEMENT
+ // For bearer, check if session start is required
+ if (manager->networkSession) {
+ // session required
+ if (manager->networkSession->isOpen() &&
+ manager->networkSession->state() == QNetworkSession::Connected) {
+ // Session is already open and ready to use.
+ // copy network session down to the backend
+ setProperty("_q_networksession", QVariant::fromValue(manager->networkSession));
+ } else {
+ // Session not ready, but can skip for loopback connections
+
+ // This is not ideal.
+ const QString host = reply->url.host();
+
+ if (host == QLatin1String("localhost") ||
+ QHostAddress(host) == QHostAddress::LocalHost ||
+ QHostAddress(host) == QHostAddress::LocalHostIPv6) {
+ // Don't need an open session for localhost access.
+ } else {
+ // need to wait for session to be opened
+ return false;
+ }
+ }
}
+#endif
- if (manager->networkSession->isOpen() &&
- manager->networkSession->state() == QNetworkSession::Connected) {
- //copy network session down to the backend
- setProperty("_q_networksession", QVariant::fromValue(manager->networkSession));
- open();
- return true;
+#ifndef QT_NO_NETWORKPROXY
+#ifndef QT_NO_BEARERMANAGEMENT
+ // Get the proxy settings from the network session (in the case of service networks,
+ // the proxy settings change depending which AP was activated)
+ QNetworkSession *session = manager->networkSession.data();
+ QNetworkConfiguration config;
+ if (session) {
+ QNetworkConfigurationManager configManager;
+ // The active configuration tells us what IAP is in use
+ QVariant v = session->sessionProperty(QLatin1String("ActiveConfiguration"));
+ if (v.isValid())
+ config = configManager.configurationFromIdentifier(qvariant_cast<QString>(v));
+ // Fallback to using the configuration if no active configuration
+ if (!config.isValid())
+ config = session->configuration();
+ // or unspecified configuration if that is no good either
+ if (!config.isValid())
+ config = QNetworkConfiguration();
}
+ reply->proxyList = manager->queryProxy(QNetworkProxyQuery(config, url()));
+#else // QT_NO_BEARERMANAGEMENT
+ // Without bearer management, the proxy depends only on the url
+ reply->proxyList = manager->queryProxy(QNetworkProxyQuery(url()));
+#endif
+#endif
- return false;
+ // now start the request
+ open();
+ return true;
}
-#endif
QT_END_NAMESPACE
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index 090a25c7f0..0749aa0595 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -1004,10 +1004,6 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
// third step: find a backend
priv->backend = d->findBackend(op, request);
-#ifndef QT_NO_NETWORKPROXY
- QList<QNetworkProxy> proxyList = d->queryProxy(QNetworkProxyQuery(request.url()));
- priv->proxyList = proxyList;
-#endif
if (priv->backend) {
priv->backend->setParent(reply);
priv->backend->reply = priv;