QNetworkAccessManager: hostInfo lookup should use proxy if set
authorMartin Petersson <martin.petersson@nokia.com>
Tue, 11 Oct 2011 14:36:55 +0000 (16:36 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 12 Oct 2011 16:01:19 +0000 (18:01 +0200)
startHostInfoLookup will try to detect if IPv4 or IPv6 will be used
when connecting to the host. If a proxy is set we should lookup
the proxy hostname instead, in case host name can't be resolved
via DNS and should be resolved by the proxy.

Task-number: QTBUG-21889
Change-Id: I2012798784fc40f153469a1298e261c52981297e
Reviewed-on: http://codereview.qt-project.org/6447
Reviewed-by: Peter Hartmann <peter.hartmann@nokia.com>
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
src/network/access/qhttpnetworkconnection.cpp

index 8f8367a..dad7136 100644 (file)
@@ -926,8 +926,16 @@ void QHttpNetworkConnectionPrivate::startHostInfoLookup()
     networkLayerState = InProgress;
 
     // check if we already now can descide if this is IPv4 or IPv6
+    QString lookupHost = hostName;
+#ifndef QT_NO_NETWORKPROXY
+    if (networkProxy.capabilities() & QNetworkProxy::HostNameLookupCapability) {
+        lookupHost = networkProxy.hostName();
+    } else if (channels[0].socket->proxy().capabilities() & QNetworkProxy::HostNameLookupCapability) {
+        lookupHost = channels[0].socket->proxy().hostName();
+    }
+#endif
     QHostAddress temp;
-    if (temp.setAddress(hostName)) {
+    if (temp.setAddress(lookupHost)) {
         if (temp.protocol() == QAbstractSocket::IPv4Protocol) {
             networkLayerState = QHttpNetworkConnectionPrivate::IPv4;
             QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection);
@@ -940,7 +948,7 @@ void QHttpNetworkConnectionPrivate::startHostInfoLookup()
     } else {
         int hostLookupId;
         bool immediateResultValid = false;
-        QHostInfo hostInfo = qt_qhostinfo_lookup(hostName,
+        QHostInfo hostInfo = qt_qhostinfo_lookup(lookupHost,
                                                  this->q_func(),
                                                  SLOT(_q_hostLookupFinished(QHostInfo)),
                                                  &immediateResultValid,