From f5fc9fa11ffb48bc74c8ac913a0d60bf2103bcb4 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Sat, 13 Nov 2021 21:23:32 -0500 Subject: [PATCH] Another auto proxy tweak --- libs/kiplatform/msw/environment.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libs/kiplatform/msw/environment.cpp b/libs/kiplatform/msw/environment.cpp index 96ac32e4b6..e30edbb447 100644 --- a/libs/kiplatform/msw/environment.cpp +++ b/libs/kiplatform/msw/environment.cpp @@ -146,8 +146,9 @@ bool KIPLATFORM::ENV::GetSystemProxyConfig( const wxString& aURL, PROXY_CONFIG& autoProxyOptions.lpszAutoConfigUrl = ieProxyConfig.lpszAutoConfigUrl; } } - else + else if( GetLastError() == ERROR_FILE_NOT_FOUND ) { + // this is the only error code where we want to continue attempting to find a proxy autoProxyDetect = true; } @@ -171,11 +172,22 @@ bool KIPLATFORM::ENV::GetSystemProxyConfig( const wxString& aURL, PROXY_CONFIG& WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A; } - autoProxyOptions.fAutoLogonIfChallenged = TRUE; + // dont do auto logon at first, this allows windows to use an cache + // per https://docs.microsoft.com/en-us/windows/win32/winhttp/autoproxy-cache + autoProxyOptions.fAutoLogonIfChallenged = FALSE; autoProxyDetect = WinHttpGetProxyForUrl( proxyResolveSession, aURL.c_str(), &autoProxyOptions, &autoProxyInfo ); + if( !autoProxyDetect && GetLastError() == ERROR_WINHTTP_LOGIN_FAILURE ) + { + autoProxyOptions.fAutoLogonIfChallenged = TRUE; + + // try again with auto login now + autoProxyDetect = WinHttpGetProxyForUrl( proxyResolveSession, aURL.c_str(), + &autoProxyOptions, &autoProxyInfo ); + } + WinHttpCloseHandle( proxyResolveSession ); }