diff --git a/src/network/kernel/qnetworkproxy_win.cpp b/src/network/kernel/qnetworkproxy_win.cpp index e801738..6df2e5e 100644 --- a/src/network/kernel/qnetworkproxy_win.cpp +++ b/src/network/kernel/qnetworkproxy_win.cpp @@ -90,6 +90,7 @@ typedef struct { #define WINHTTP_AUTOPROXY_AUTO_DETECT 0x00000001 #define WINHTTP_AUTOPROXY_CONFIG_URL 0x00000002 + #define WINHTTP_AUTO_DETECT_TYPE_DHCP 0x00000001 #define WINHTTP_AUTO_DETECT_TYPE_DNS_A 0x00000002 @@ -100,6 +101,10 @@ typedef struct { #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 +325,7 @@ void QWindowsSystemProxy::init() 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 +382,26 @@ QList QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro // 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 +416,13 @@ QList QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro } // 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; }