mirror of
https://github.com/cemu-project/vcpkg.git
synced 2025-02-22 18:47:09 +01:00
[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>
This commit is contained in:
parent
102179f879
commit
e3dfd4a9fa
@ -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})
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user