diff options
author | Adrien Bustany <adrien.bustany@nokia.com> | 2012-04-23 10:49:11 +0300 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-01 14:56:38 +0200 |
commit | 3013758f17beecb55bc40d28beef5b55f83dec2a (patch) | |
tree | a80c3fa015910823b0b5e1936716638827cb5bd0 /src/network/kernel/qnetworkproxy_generic.cpp | |
parent | 2149b650ea1f4efb174a8559a4621c467492e4a0 (diff) |
QNetworkProxyFactory: check the "no_proxy" environment variable
The QNetworkProxyFactory class considered the http_proxy environment
variable, but not the no_proxy one. This commit adds no_proxy handling,
loosely modeled after the way curl does it.
Change-Id: Ibb9e5ffcb30fed5c95dc9fc3bc4177e20d025a50
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
Diffstat (limited to 'src/network/kernel/qnetworkproxy_generic.cpp')
-rw-r--r-- | src/network/kernel/qnetworkproxy_generic.cpp | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/network/kernel/qnetworkproxy_generic.cpp b/src/network/kernel/qnetworkproxy_generic.cpp index c0c6b9fe42..66053b0b47 100644 --- a/src/network/kernel/qnetworkproxy_generic.cpp +++ b/src/network/kernel/qnetworkproxy_generic.cpp @@ -47,16 +47,50 @@ #ifndef QT_NO_NETWORKPROXY /* - * Construct a proxy from the environment variable http_proxy. + * Construct a proxy from the environment variables http_proxy and no_proxy. * Or no system proxy. Just return a list with NoProxy. */ QT_BEGIN_NAMESPACE -QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &) +static bool ignoreProxyFor(const QNetworkProxyQuery &query) +{ + const QList<QByteArray> noProxyTokens = qgetenv("no_proxy").split(','); + + foreach (const QByteArray rawToken, noProxyTokens) { + QByteArray token = rawToken.trimmed(); + QString peerHostName = query.peerHostName(); + + // Since we use suffix matching, "*" is our 'default' behaviour + if (token.startsWith("*")) + token = token.mid(1); + + // Harmonize trailing dot notation + if (token.endsWith('.') && !peerHostName.endsWith('.')) + token = token.left(token.length()-1); + + // We prepend a dot to both values, so that when we do a suffix match, + // we don't match "donotmatch.com" with "match.com" + if (!token.startsWith('.')) + token.prepend('.'); + + if (!peerHostName.startsWith('.')) + peerHostName.prepend('.'); + + if (peerHostName.endsWith(QString::fromLatin1(token))) + return true; + } + + return false; +} + +QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query) { QList<QNetworkProxy> proxyList; + if (ignoreProxyFor(query)) + return proxyList << QNetworkProxy::NoProxy; + QByteArray proxy_env = qgetenv("http_proxy"); if (!proxy_env.isEmpty()) { QUrl url = QUrl(QString::fromLocal8Bit(proxy_env)); |