QNativeSocketEngine - set query type in checkProxy

The default query type for QNetworkProxyQuery is TcpSocket (that's what
our QNetworkProxy::applicationProxy() requests). Unfortunately, this
can result in http_proxy found and QTcpServer::listen() failing
(probably, QUdpSocket is also affected). So now we extract applicationProxy's
logic but modify it to provide the exact query type we need.

Task-number: QTBUG-58706
Task-number: QTBUG-41053
Task-number: QTBUG-58374
Change-Id: I79ce0efb779bbaf08afd78c44cbe92d08730152b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Timur Pocheptsov 2017-02-20 16:25:51 +01:00
parent b48e960969
commit c0157a9f03

View File

@ -358,17 +358,41 @@ bool QNativeSocketEnginePrivate::checkProxy(const QHostAddress &address)
#if !defined(QT_NO_NETWORKPROXY)
QObject *parent = q_func()->parent();
QNetworkProxy proxy;
QNetworkProxyQuery::QueryType queryType = QNetworkProxyQuery::TcpSocket;
if (QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(parent)) {
proxy = socket->proxy();
switch (socket->socketType()) {
case QAbstractSocket::UdpSocket:
queryType = QNetworkProxyQuery::UdpSocket;
break;
case QAbstractSocket::SctpSocket:
queryType = QNetworkProxyQuery::SctpSocket;
break;
case QAbstractSocket::TcpSocket:
case QAbstractSocket::UnknownSocketType:
queryType = QNetworkProxyQuery::TcpSocket;
}
} else if (QTcpServer *server = qobject_cast<QTcpServer *>(parent)) {
proxy = server->proxy();
queryType = QNetworkProxyQuery::TcpServer;
#ifndef QT_NO_SCTP
if (qobject_cast<QSctpServer *>(server))
queryType = QNetworkProxyQuery::SctpServer;
#endif
} else {
// no parent -> no proxy
return true;
}
if (proxy.type() == QNetworkProxy::DefaultProxy)
proxy = QNetworkProxy::applicationProxy();
if (proxy.type() == QNetworkProxy::DefaultProxy) {
// This is similar to what we have in QNetworkProxy::applicationProxy,
// the only difference is that we provide the correct query type instead of
// always using TcpSocket unconditionally (this is the default type for
// QNetworkProxyQuery).
QNetworkProxyQuery query;
query.setQueryType(queryType);
proxy = QNetworkProxyFactory::systemProxyForQuery(query).constFirst();
}
if (proxy.type() != QNetworkProxy::DefaultProxy &&
proxy.type() != QNetworkProxy::NoProxy) {