Skip to content

Commit

Permalink
update curl transport options to support ignore proxy from system (#3564
Browse files Browse the repository at this point in the history
)

* update curl transport options to support ignore proxy from system

* update changelog

* bug fix for cl
  • Loading branch information
vhvb1989 authored Apr 25, 2022
1 parent 075b8d0 commit bdb7124
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Updated field type `CurlTransportOptions.Proxy` from `std::string` to `Azure::Nullable<std::string>`. This change allow to se an empty string to make libcurl ignore proxy settings from environment [](https://github.com/Azure/azure-sdk-for-cpp/issues/3537).

### Other Changes

## 1.5.0 (2022-03-31)
Expand Down
8 changes: 6 additions & 2 deletions sdk/core/azure-core/inc/azure/core/http/curl_transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@ namespace Azure { namespace Core { namespace Http {
struct CurlTransportOptions final
{
/**
* @brief The string for the proxy is passed directly to the libcurl handle without any parsing
* @brief The string for the proxy is passed directly to the libcurl handle without any parsing.
*
* @details libcurl will use system's environment proxy configuration (if it is set) when the \p
* Proxy setting is not set (is null). Setting an empty string will make libcurl to ignore any
* proxy settings from the system (use no proxy).
*
* @remark No validation for the string is done by the Azure SDK. More about this option:
* https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html.
*
* @remark The default value is an empty string (no proxy).
*
*/
std::string Proxy;
Azure::Nullable<std::string> Proxy;
/**
* @brief The string for the certificate authenticator is sent to libcurl handle directly.
*
Expand Down
8 changes: 4 additions & 4 deletions sdk/core/azure-core/src/http/curl/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ inline std::string GetConnectionKey(std::string const& host, CurlTransportOption
{
std::string key(host);
key.append(!options.CAInfo.empty() ? options.CAInfo : "0");
key.append(!options.Proxy.empty() ? options.Proxy : "0");
key.append(options.Proxy ? (options.Proxy->empty() ? "NoProxy" : options.Proxy.Value()) : "0");
key.append(!options.SslOptions.EnableCertificateRevocationListCheck ? "1" : "0");
key.append(options.SslVerifyPeer ? "1" : "0");
key.append(options.NoSignal ? "1" : "0");
Expand Down Expand Up @@ -1356,13 +1356,13 @@ std::unique_ptr<CurlNetworkConnection> CurlConnectionPool::ExtractOrCreateCurlCo
/******************** Curl handle options apply to all connections created
* The keepAlive option is managed by the session directly.
*/
if (!options.Proxy.empty())
if (options.Proxy)
{
if (!SetLibcurlOption(newHandle, CURLOPT_PROXY, options.Proxy.c_str(), &result))
if (!SetLibcurlOption(newHandle, CURLOPT_PROXY, options.Proxy->c_str(), &result))
{
throw Azure::Core::Http::TransportException(
_detail::DefaultFailedToGetNewConnectionTemplate + hostDisplayName
+ ". Failed to set proxy to:" + options.Proxy + ". "
+ ". Failed to set proxy to:" + options.Proxy.Value() + ". "
+ std::string(curl_easy_strerror(result)));
}
}
Expand Down

0 comments on commit bdb7124

Please sign in to comment.