expose Curl nosignal opt (#2985)

* add NoSignalOption

* cl

* tests
This commit is contained in:
Victor Vazquez 2021-10-21 17:25:02 -07:00 committed by GitHub
parent 5ad55ecb6e
commit ef72f3c8a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 39 deletions

View File

@ -5,6 +5,7 @@
### Features Added
- Add the static libcurl transport adapter.
- Add `NoSignal` option to the `curlTransportAdapter`.
### Breaking Changes

View File

@ -88,6 +88,16 @@ namespace Azure { namespace Core { namespace Http {
*
*/
CurlTransportSslOptions SslOptions;
/**
* @brief When true, libcurl will not use any functions that install signal handlers or any
* functions that cause signals to be sent to the process.
*
* @details This option is here to allow multi-threaded unix applications to still set/use all
* timeout options etc, without risking getting signals.
*
*/
bool NoSignal = false;
};
/**

View File

@ -93,6 +93,16 @@ namespace Azure { namespace Core { namespace Http {
*
*/
StaticCurlTransportSslOptions SslOptions;
/**
* @brief When true, libcurl will not use any functions that install signal handlers or any
* functions that cause signals to be sent to the process.
*
* @details This option is here to allow multi-threaded unix applications to still set/use all
* timeout options etc, without risking getting signals.
*
*/
bool NoSignal = false;
};
/**

View File

@ -1226,38 +1226,12 @@ namespace {
inline std::string GetConnectionKey(std::string const& host, CurlTransportOptions const& options)
{
std::string key(host);
if (!options.CAInfo.empty())
{
key.append(options.CAInfo);
}
else
{
key.append("0");
}
if (!options.Proxy.empty())
{
key.append(options.Proxy);
}
else
{
key.append("0");
}
if (!options.SslOptions.EnableCertificateRevocationListCheck)
{
key.append("1");
}
else
{
key.append("0");
}
if (options.SslVerifyPeer)
{
key.append("1");
}
else
{
key.append("0");
}
key.append(!options.CAInfo.empty() ? options.CAInfo : "0");
key.append(!options.Proxy.empty() ? options.Proxy : "0");
key.append(!options.SslOptions.EnableCertificateRevocationListCheck ? "1" : "0");
key.append(options.SslVerifyPeer ? "1" : "0");
key.append(options.NoSignal ? "1" : "0");
return key;
}
} // namespace
@ -1402,7 +1376,17 @@ std::unique_ptr<CurlNetworkConnection> CurlConnectionPool::ExtractOrCreateCurlCo
{
throw Azure::Core::Http::TransportException(
_detail::DefaultFailedToGetNewConnectionTemplate + host
+ ". Failed to disable ssl verify peer." + ". "
+ ". Failed to disable ssl verify peer. " + std::string(curl_easy_strerror(result)));
}
}
if (options.NoSignal)
{
if (!SetLibcurlOption(newHandle, CURLOPT_NOSIGNAL, 1L, &result))
{
throw Azure::Core::Http::TransportException(
_detail::DefaultFailedToGetNewConnectionTemplate + host
+ ". Failed to set NOSIGNAL option for libcurl. "
+ std::string(curl_easy_strerror(result)));
}
}

View File

@ -289,6 +289,17 @@ public:
}
}
if (m_options.NoSignal)
{
if (!SetStaticLibcurlOption(m_libcurlHandle, CURLOPT_NOSIGNAL, 1L, &result))
{
throw Azure::Core::Http::TransportException(
FailedToGetNewConnectionTemplate + host
+ ". Failed to set NOSIGNAL option for libcurl. "
+ std::string(curl_easy_strerror(result)));
}
}
// headers sep-up
auto const& headers = request.GetHeaders();
if (headers.size() > 0)

View File

@ -45,7 +45,7 @@ namespace Azure { namespace Core { namespace Test {
Azure::Core::Http::Request req(
Azure::Core::Http::HttpMethod::Get, Azure::Core::Url(AzureSdkHttpbinServer::Get()));
std::string const expectedConnectionKey
= AzureSdkHttpbinServer::Schema() + AzureSdkHttpbinServer::Host() + "0011";
= AzureSdkHttpbinServer::Schema() + AzureSdkHttpbinServer::Host() + "00110";
{
// Creating a new connection with default options
@ -114,7 +114,7 @@ namespace Azure { namespace Core { namespace Test {
// Now test that using a different connection config won't re-use the same connection
std::string const secondExpectedKey
= AzureSdkHttpbinServer::Schema() + AzureSdkHttpbinServer::Host() + "0010";
= AzureSdkHttpbinServer::Schema() + AzureSdkHttpbinServer::Host() + "00100";
{
// Creating a new connection with options
Azure::Core::Http::CurlTransportOptions options;
@ -394,7 +394,7 @@ namespace Azure { namespace Core { namespace Test {
Azure::Core::Http::Request req(
Azure::Core::Http::HttpMethod::Get, Azure::Core::Url(authority));
std::string const expectedConnectionKey
= AzureSdkHttpbinServer::Schema() + AzureSdkHttpbinServer::Host() + "0011";
= AzureSdkHttpbinServer::Schema() + AzureSdkHttpbinServer::Host() + "00110";
// Creating a new connection with default options
auto connection = Azure::Core::Http::_detail::CurlConnectionPool::g_curlConnectionPool
@ -430,7 +430,7 @@ namespace Azure { namespace Core { namespace Test {
Azure::Core::Http::Request req(
Azure::Core::Http::HttpMethod::Get, Azure::Core::Url(authority));
std::string const expectedConnectionKey
= AzureSdkHttpbinServer::Schema() + AzureSdkHttpbinServer::Host() + "4430011";
= AzureSdkHttpbinServer::Schema() + AzureSdkHttpbinServer::Host() + "44300110";
// Creating a new connection with default options
auto connection = Azure::Core::Http::_detail::CurlConnectionPool::g_curlConnectionPool
@ -467,7 +467,7 @@ namespace Azure { namespace Core { namespace Test {
Azure::Core::Http::Request req(
Azure::Core::Http::HttpMethod::Get, Azure::Core::Url(authority));
std::string const expectedConnectionKey
= AzureSdkHttpbinServer::Schema() + AzureSdkHttpbinServer::Host() + "0011";
= AzureSdkHttpbinServer::Schema() + AzureSdkHttpbinServer::Host() + "00110";
// Creating a new connection with default options
auto connection = Azure::Core::Http::_detail::CurlConnectionPool::g_curlConnectionPool
@ -502,7 +502,7 @@ namespace Azure { namespace Core { namespace Test {
Azure::Core::Http::Request req(
Azure::Core::Http::HttpMethod::Get, Azure::Core::Url(authority));
std::string const expectedConnectionKey
= AzureSdkHttpbinServer::Schema() + AzureSdkHttpbinServer::Host() + "4430011";
= AzureSdkHttpbinServer::Schema() + AzureSdkHttpbinServer::Host() + "44300110";
// Creating a new connection with default options
auto connection = Azure::Core::Http::_detail::CurlConnectionPool::g_curlConnectionPool