src/network/kernel/qnetworkproxy_win.cpp
changeset 33 3e2da88830cd
parent 18 2f34d5167611
--- a/src/network/kernel/qnetworkproxy_win.cpp	Tue Jul 06 15:10:48 2010 +0300
+++ b/src/network/kernel/qnetworkproxy_win.cpp	Wed Aug 18 10:37:55 2010 +0300
@@ -100,6 +100,10 @@
 #define WINHTTP_NO_PROXY_NAME     NULL
 #define WINHTTP_NO_PROXY_BYPASS   NULL
 
+#define WINHTTP_ERROR_BASE                      12000
+#define ERROR_WINHTTP_LOGIN_FAILURE             (WINHTTP_ERROR_BASE + 15)
+#define ERROR_WINHTTP_AUTODETECTION_FAILED      (WINHTTP_ERROR_BASE + 180)
+
 QT_BEGIN_NAMESPACE
 
 typedef BOOL (WINAPI * PtrWinHttpGetProxyForUrl)(HINTERNET, LPCWSTR, WINHTTP_AUTOPROXY_OPTIONS*, WINHTTP_PROXY_INFO*);
@@ -320,7 +324,7 @@
 
         isAutoConfig = true;
         memset(&autoProxyOptions, 0, sizeof autoProxyOptions);
-        autoProxyOptions.fAutoLogonIfChallenged = true;
+        autoProxyOptions.fAutoLogonIfChallenged = false;
         if (ieProxyConfig.fAutoDetect) {
             autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT;
             autoProxyOptions.dwAutoDetectFlags = WINHTTP_AUTO_DETECT_TYPE_DHCP |
@@ -377,10 +381,26 @@
             // change the scheme to https, maybe it'll work
             url.setScheme(QLatin1String("https"));
         }
-        if (ptrWinHttpGetProxyForUrl(sp->hHttpSession,
-                                     (LPCWSTR)url.toString().utf16(),
-                                     &sp->autoProxyOptions,
-                                     &proxyInfo)) {
+
+        bool getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession,
+                                                (LPCWSTR)url.toString().utf16(),
+                                                &sp->autoProxyOptions,
+                                                &proxyInfo);
+        DWORD getProxyError = GetLastError();
+
+        if (!getProxySucceeded
+            && (ERROR_WINHTTP_LOGIN_FAILURE == getProxyError)) {
+            // We first tried without AutoLogon, because this might prevent caching the result.
+            // But now we've to enable it (http://msdn.microsoft.com/en-us/library/aa383153%28v=VS.85%29.aspx)
+            sp->autoProxyOptions.fAutoLogonIfChallenged = TRUE;
+            getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession,
+                                               (LPCWSTR)url.toString().utf16(),
+                                                &sp->autoProxyOptions,
+                                                &proxyInfo);
+            getProxyError = GetLastError();
+        }
+
+        if (getProxySucceeded) {
             // yes, we got a config for this URL
             QString proxyBypass = QString::fromWCharArray(proxyInfo.lpszProxyBypass);
             QStringList proxyServerList = splitSpaceSemicolon(QString::fromWCharArray(proxyInfo.lpszProxy));
@@ -395,6 +415,13 @@
         }
 
         // GetProxyForUrl failed
+
+        if (ERROR_WINHTTP_AUTODETECTION_FAILED == getProxyError) {
+            //No config file could be retrieved on the network.
+            //Don't search for it next time again.
+            sp->isAutoConfig = false;
+        }
+
         return sp->defaultResult;
     }