diff options
| author | xabbudm <dmuhle@gmail.com> | 2020-01-16 22:56:28 +0100 |
|---|---|---|
| committer | Victor Romero <romerosanchezv@gmail.com> | 2020-01-16 13:56:28 -0800 |
| commit | e3dfd4a9fa25c05abcf166a1b3bb260b542ed598 (patch) | |
| tree | 8a0e39bc9691971d35c63f4fbc82029fc1b22fc9 /toolsrc/src | |
| parent | 102179f8793f90e5a24a30c5e7364008d5865ec8 (diff) | |
| download | vcpkg-e3dfd4a9fa25c05abcf166a1b3bb260b542ed598.tar.gz vcpkg-e3dfd4a9fa25c05abcf166a1b3bb260b542ed598.zip | |
[VCPKG] WinHTTPOption for company Proxy not correctly taken into account (#9372)
* fixes to get vcpkg up and running when behind corporate proxy
* clean up of code to check if HTTP_PROXY environment variable is set
* fixed compiler errors for non win32 systems
* [vcpkg] Simplify HTTPS_PROXY code for WinHTTP
Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
Diffstat (limited to 'toolsrc/src')
| -rw-r--r-- | toolsrc/src/vcpkg/base/downloads.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/toolsrc/src/vcpkg/base/downloads.cpp b/toolsrc/src/vcpkg/base/downloads.cpp index df6b1be09..995e2d4f3 100644 --- a/toolsrc/src/vcpkg/base/downloads.cpp +++ b/toolsrc/src/vcpkg/base/downloads.cpp @@ -2,13 +2,12 @@ #include <vcpkg/base/downloads.h> #include <vcpkg/base/hash.h> +#include <vcpkg/base/system.h> #include <vcpkg/base/system.process.h> #include <vcpkg/base/util.h> #if defined(_WIN32) #include <VersionHelpers.h> -#else -#include <vcpkg/base/system.h> #endif namespace vcpkg::Downloads @@ -43,8 +42,22 @@ namespace vcpkg::Downloads 0); Checks::check_exit(VCPKG_LINE_INFO, hSession, "WinHttpOpen() failed: %d", GetLastError()); + // If the environment variable HTTPS_PROXY is set + // use that variable as proxy. This situation might exist when user is in a company network + // with restricted network/proxy settings + auto maybe_https_proxy_env = System::get_environment_variable("HTTPS_PROXY"); + if (auto p_https_proxy = maybe_https_proxy_env.get()) + { + std::wstring env_proxy_settings = Strings::to_utf16(*p_https_proxy); + WINHTTP_PROXY_INFO proxy; + proxy.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY; + proxy.lpszProxy = env_proxy_settings.data(); + proxy.lpszProxyBypass = nullptr; + + WinHttpSetOption(hSession, WINHTTP_OPTION_PROXY, &proxy, sizeof(proxy)); + } // Win7 IE Proxy fallback - if (IsWindows7OrGreater() && !IsWindows8Point1OrGreater()) + else if (IsWindows7OrGreater() && !IsWindows8Point1OrGreater()) { // First check if any proxy has been found automatically WINHTTP_PROXY_INFO proxyInfo; @@ -63,6 +76,9 @@ namespace vcpkg::Downloads proxy.lpszProxy = ieProxy.lpszProxy; proxy.lpszProxyBypass = ieProxy.lpszProxyBypass; WinHttpSetOption(hSession, WINHTTP_OPTION_PROXY, &proxy, sizeof(proxy)); + GlobalFree(ieProxy.lpszProxy); + GlobalFree(ieProxy.lpszProxyBypass); + GlobalFree(ieProxy.lpszAutoConfigUrl); } } } @@ -89,6 +105,7 @@ namespace vcpkg::Downloads // Send a request. auto bResults = WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0); + Checks::check_exit(VCPKG_LINE_INFO, bResults, "WinHttpSendRequest() failed: %d", GetLastError()); // End the request. |
