Skip to content

Commit

Permalink
Allow usage of system default proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Ryabinin authored and SergeyRyabinin committed Sep 21, 2023
1 parent b054124 commit a3a39d0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ namespace Aws
* Override the http endpoint used to talk to a service.
*/
Aws::String endpointOverride;

/**
* Allow HTTP client to discover system proxy setting. Off by default for legacy reasons.
*/
bool allowSystemProxy = false;
/**
* If you have users going through a proxy, set the proxy scheme here. Default HTTP
*/
Expand Down
11 changes: 6 additions & 5 deletions src/aws-cpp-sdk-core/include/aws/core/http/curl/CurlHttpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class AWS_CORE_API CurlHttpClient: public HttpClient

private:
mutable CurlHandleContainer m_curlHandleContainer;
bool m_isUsingProxy;
bool m_isAllowSystemProxy = false;
bool m_isUsingProxy = false;
Aws::String m_proxyUserName;
Aws::String m_proxyPassword;
Aws::String m_proxyScheme;
Expand All @@ -59,13 +60,13 @@ class AWS_CORE_API CurlHttpClient: public HttpClient
Aws::String m_proxySSLKeyPath;
Aws::String m_proxySSLKeyType;
Aws::String m_proxyKeyPasswd;
unsigned m_proxyPort;
unsigned m_proxyPort = 0;
Aws::String m_nonProxyHosts;
bool m_verifySSL;
bool m_verifySSL = true;
Aws::String m_caPath;
Aws::String m_caFile;
bool m_disableExpectHeader;
bool m_allowRedirects;
bool m_disableExpectHeader = false;
bool m_allowRedirects = false;
static std::atomic<bool> isInit;
std::shared_ptr<smithy::components::tracing::TelemetryProvider> m_telemetryProvider;
};
Expand Down
7 changes: 5 additions & 2 deletions src/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ CurlHttpClient::CurlHttpClient(const ClientConfiguration& clientConfig) :
Base(),
m_curlHandleContainer(clientConfig.maxConnections, clientConfig.httpRequestTimeoutMs, clientConfig.connectTimeoutMs, clientConfig.enableTcpKeepAlive,
clientConfig.tcpKeepAliveIntervalMs, clientConfig.requestTimeoutMs, clientConfig.lowSpeedLimit, clientConfig.version),
m_isUsingProxy(!clientConfig.proxyHost.empty()), m_proxyUserName(clientConfig.proxyUserName),
m_isAllowSystemProxy(clientConfig.allowSystemProxy), m_isUsingProxy(!clientConfig.proxyHost.empty()), m_proxyUserName(clientConfig.proxyUserName),
m_proxyPassword(clientConfig.proxyPassword), m_proxyScheme(SchemeMapper::ToString(clientConfig.proxyScheme)), m_proxyHost(clientConfig.proxyHost),
m_proxySSLCertPath(clientConfig.proxySSLCertPath), m_proxySSLCertType(clientConfig.proxySSLCertType),
m_proxySSLKeyPath(clientConfig.proxySSLKeyPath), m_proxySSLKeyType(clientConfig.proxySSLKeyType),
Expand Down Expand Up @@ -763,7 +763,10 @@ std::shared_ptr<HttpResponse> CurlHttpClient::MakeRequest(const std::shared_ptr<
}
else
{
curl_easy_setopt(connectionHandle, CURLOPT_PROXY, "");
if(!m_isAllowSystemProxy)
{
curl_easy_setopt(connectionHandle, CURLOPT_PROXY, "");
}
}

if (request->GetContentBody())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ WinHttpSyncHttpClient::WinHttpSyncHttpClient(const ClientConfiguration& config)
AWS_LOGSTREAM_INFO(GetLogTag(), "Creating http client with user agent " << config.userAgent << " with max connections " << config.maxConnections
<< " request timeout " << config.requestTimeoutMs << ",and connect timeout " << config.connectTimeoutMs);

DWORD winhttpFlags = WINHTTP_ACCESS_TYPE_NO_PROXY;
#if defined(WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY)
DWORD winhttpFlags = config.allowSystemProxy ? WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY : WINHTTP_ACCESS_TYPE_NO_PROXY;
#else
DWORD winhttpFlags = config.allowSystemProxy ? WINHTTP_ACCESS_TYPE_DEFAULT_PROXY : WINHTTP_ACCESS_TYPE_NO_PROXY;
#endif
const char* proxyHosts = nullptr;
Aws::String strProxyHosts;

Expand Down

0 comments on commit a3a39d0

Please sign in to comment.