BB10 systemProxyForQuery: query system proxy also for non-URL requests

... like e.g. in QAbstractSocket::connectToHost().
We can set the scheme on the query URL based on well-known ports; even
if the port is not well-known, we can just query the URL anyhow and let
the netstatus API resolve the right proxy for us.

In addition, return early for local schemes like "file" and "qrc".

Task-number: QTBUG-29425
Change-Id: I900f1ecbac6dd380bb8a77470b39de2c07aa7f6e
Reviewed-by: Andrey Leonov <aleonov@rim.com>
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
This commit is contained in:
Peter Hartmann 2013-02-07 17:02:48 +01:00 committed by The Qt Project
parent d57e9b35c9
commit 28d526db74
2 changed files with 28 additions and 4 deletions

View File

@ -1562,7 +1562,7 @@ void QNetworkProxyFactory::setApplicationProxyFactory(QNetworkProxyFactory *fact
\li On Windows platforms, this function may take several seconds to
execute depending on the configuration of the user's system.
\li On BlackBerry, only UrlRequest queries are supported. SOCKS is
\li On BlackBerry, only UrlRequest and TcpSocket queries are supported. SOCKS is
not supported. The proxy credentials are only retrieved for the
default configuration.
\endlist

View File

@ -63,14 +63,36 @@ QT_BEGIN_NAMESPACE
QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query)
{
QNetworkProxy proxy;
if (query.url().scheme() == QLatin1String("file")
|| query.url().scheme() == QLatin1String("qrc"))
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
if (query.queryType() != QNetworkProxyQuery::UrlRequest) {
if (query.queryType() != QNetworkProxyQuery::UrlRequest
&& query.queryType() != QNetworkProxyQuery::TcpSocket) {
qWarning("Unsupported query type: %d", query.queryType());
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
}
QUrl url = query.url();
QUrl url;
if (query.queryType() == QNetworkProxyQuery::UrlRequest) {
url = query.url();
} else if (query.queryType() == QNetworkProxyQuery::TcpSocket
&& !query.peerHostName().isEmpty()) {
url.setHost(query.peerHostName());
switch (query.peerPort()) {
case 443:
url.setScheme(QStringLiteral("https"));
break;
case 21:
url.setScheme(QStringLiteral("ftp"));
break;
default:
// for unknown ports, we just pretend we are dealing
// with a HTTP URL, otherwise we will not get a proxy
// from the netstatus API
url.setScheme(QStringLiteral("http"));
}
}
if (!url.isValid()) {
qWarning("Invalid URL: %s", qPrintable(url.toString()));
@ -112,6 +134,8 @@ QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
}
QNetworkProxy proxy;
QString protocol = query.protocolTag();
if (protocol.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) { // http, https
proxy.setType((QNetworkProxy::HttpProxy));