From c6d553b2a2d39bc98773ab26659acc1901064dfa Mon Sep 17 00:00:00 2001 From: Sushrut Shringarputale Date: Tue, 20 May 2025 21:59:01 -0700 Subject: [PATCH] Fix Windows error for failing curl SSL cache (#6582) * Fix Windows error for failing curl SSL cache * Fix unused parameter warning in win_http_transport.cpp, as in #6579 * Update changelog, cspell, and conditional init m_sslShareHandle --------- Co-authored-by: Anton Kolesnyk --- .vscode/cspell.json | 1 + sdk/core/azure-core/CHANGELOG.md | 2 +- sdk/core/azure-core/src/http/curl/curl.cpp | 19 ++++++++++--------- .../src/http/winhttp/win_http_transport.cpp | 4 ++++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.vscode/cspell.json b/.vscode/cspell.json index f223e1a56..5df529dd9 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -263,6 +263,7 @@ "stoull", "STREQ", "Sushrut", + "sushshring", "Sutou", "testid", "swedencentral", diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index eabb0e43c..7724d5891 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -4,7 +4,7 @@ ### Features Added -- [[#6535]](https://github.com/Azure/azure-sdk-for-cpp/issues/6535) Enable SSL caching for libcurl transport by default, which is backwards compatible behavior with older libcurl versions, so using the default settings won't result in transport error when using libcurl >= 8.12. The option is controlled by `CurlTransportOptions::EnableCurlSslCaching`, and is on by default. (A community contribution, courtesy of _[chewi](https://github.com/sushshring)_) +- [[#6535]](https://github.com/Azure/azure-sdk-for-cpp/issues/6535) Enable SSL caching for libcurl transport by default, which is backwards compatible behavior with older libcurl versions, so using the default settings won't result in transport error when using libcurl >= 8.12. The option is controlled by `CurlTransportOptions::EnableCurlSslCaching`, and is on by default. (A community contribution, courtesy of _[sushshring](https://github.com/sushshring)_) ### Breaking Changes diff --git a/sdk/core/azure-core/src/http/curl/curl.cpp b/sdk/core/azure-core/src/http/curl/curl.cpp index 3ca3ef575..b97d898a7 100644 --- a/sdk/core/azure-core/src/http/curl/curl.cpp +++ b/sdk/core/azure-core/src/http/curl/curl.cpp @@ -2314,14 +2314,6 @@ CurlConnection::CurlConnection( } CURLcode result; - m_sslShareHandle = std::make_unique(); - if (!m_sslShareHandle->share_handle) - { - throw Azure::Core::Http::TransportException( - _detail::DefaultFailedToGetNewConnectionTemplate + hostDisplayName + ". " - + std::string("curl_share_init returned Null")); - } - if (!options.EnableCurlSslCaching) { // Disable SSL session ID caching @@ -2334,6 +2326,15 @@ CurlConnection::CurlConnection( } else { + m_sslShareHandle = std::make_unique(); + + if (!m_sslShareHandle->share_handle) + { + throw Azure::Core::Http::TransportException( + _detail::DefaultFailedToGetNewConnectionTemplate + hostDisplayName + ". " + + std::string("curl_share_init returned Null")); + } + CURLSHcode shResult; if (!SetLibcurlShareOption( m_sslShareHandle, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION, &shResult)) @@ -2343,7 +2344,7 @@ CurlConnection::CurlConnection( + std::string(curl_share_strerror(shResult))); } - if (!SetLibcurlOption(m_handle, CURLOPT_SHARE, m_sslShareHandle.get(), &result)) + if (!SetLibcurlOption(m_handle, CURLOPT_SHARE, m_sslShareHandle->share_handle, &result)) { throw Azure::Core::Http::TransportException( _detail::DefaultFailedToGetNewConnectionTemplate + hostDisplayName + ". " diff --git a/sdk/core/azure-core/src/http/winhttp/win_http_transport.cpp b/sdk/core/azure-core/src/http/winhttp/win_http_transport.cpp index 342cc3531..3ff991e70 100644 --- a/sdk/core/azure-core/src/http/winhttp/win_http_transport.cpp +++ b/sdk/core/azure-core/src/http/winhttp/win_http_transport.cpp @@ -1670,6 +1670,10 @@ namespace Azure { namespace Core { namespace Http { namespace _detail { std::unique_ptr WinHttpRequest::SendRequestAndGetResponse(HttpMethod requestMethod) { + // Suppress unused parameter warning (C4100). + // Keeping 'requestMethod' in the signature preserves API compatibility. + (void)requestMethod; + // First, use WinHttpQueryHeaders to obtain the size of the buffer. // The call is expected to fail since no destination buffer is provided. DWORD sizeOfHeaders = 0;