From e3dfd4a9fa25c05abcf166a1b3bb260b542ed598 Mon Sep 17 00:00:00 2001 From: xabbudm Date: Thu, 16 Jan 2020 22:56:28 +0100 Subject: [PATCH] [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 --- ports/python3/portfile.cmake | 2 +- toolsrc/src/vcpkg/base/downloads.cpp | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ports/python3/portfile.cmake b/ports/python3/portfile.cmake index 3a22d25b7..bbb5de173 100644 --- a/ports/python3/portfile.cmake +++ b/ports/python3/portfile.cmake @@ -19,7 +19,7 @@ vcpkg_from_github( ) if (VCPKG_TARGET_IS_WINDOWS) - set(SOURCE_PATH "${TEMP_SOURCE_PATH}-Lib-${VCPKG_LIBRARY_LINKAGE}-crt-${VCPKG_CRT_LINKAGE}") + set(SOURCE_PATH "${TEMP_SOURCE_PATH}-Lib-Win") file(REMOVE_RECURSE ${SOURCE_PATH}) file(RENAME "${TEMP_SOURCE_PATH}" ${SOURCE_PATH}) 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 #include +#include #include #include #if defined(_WIN32) #include -#else -#include #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.