diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index ef7f61fd2..1a5d0a81a 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -4,7 +4,6 @@ ### Features Added -- Add the static libcurl transport adapter. - Add `NoSignal` option to the `CurlTransportAdapter`. - Add `ConnectionTimeout` option to the `CurlTransportAdapter`. - Add `Azure::Core::Http::Request` constructor overload to support payload and non-buffered response. diff --git a/sdk/core/azure-core/CMakeLists.txt b/sdk/core/azure-core/CMakeLists.txt index d7def404d..85327c595 100644 --- a/sdk/core/azure-core/CMakeLists.txt +++ b/sdk/core/azure-core/CMakeLists.txt @@ -39,12 +39,13 @@ if(BUILD_TRANSPORT_CURL) src/http/curl/curl_connection_pool_private.hpp src/http/curl/curl_connection_private.hpp src/http/curl/curl_session_private.hpp + src/http/curl/static_curl_transport.hpp src/http/curl/curl.cpp src/http/curl/static_curl.cpp ) SET(CURL_TRANSPORT_ADAPTER_INC inc/azure/core/http/curl_transport.hpp - inc/azure/core/http/static_curl_transport.hpp) + ) endif() if(BUILD_TRANSPORT_WINHTTP) SET(WIN_TRANSPORT_ADAPTER_SRC src/http/winhttp/win_http_transport.cpp) diff --git a/sdk/core/azure-core/inc/azure/core/http/static_curl_transport.hpp b/sdk/core/azure-core/inc/azure/core/http/static_curl_transport.hpp deleted file mode 100644 index fedb70b91..000000000 --- a/sdk/core/azure-core/inc/azure/core/http/static_curl_transport.hpp +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -/** - * @file - * @brief #Azure::Core::Http::HttpTransport static implementation using libcurl won't produce real - * response streams. The HTTP responses are first statically downloaded within the transport - * adapter. - * - * @remark This transport adapater is less efficient than the non-static version. Use this - * implementation where performance ( memory and time ) is not a concern. - */ - -#pragma once - -#include "azure/core/context.hpp" -#include "azure/core/http/http.hpp" -#include "azure/core/http/transport.hpp" - -namespace Azure { namespace Core { namespace Http { - - /** - * @brief The available options to set libcurl SSL options. - * - * @remark The SDK will map the enum option to libcurl's specific option. See more info here: - * https://curl.haxx.se/libcurl/c/CURLOPT_SSL_OPTIONS.html - * - */ - struct StaticCurlTransportSslOptions final - { - /** - * @brief This option can enable the revocation list check. - * - * @remark Libcurl does revocation list check by default for SSL backends that supports this - * feature. However, the Azure SDK overrides libcurl's behavior and disables the revocation list - * check by default. - * - */ - bool EnableCertificateRevocationListCheck = false; - }; - - /** - * @brief Set the libcurl connection options like a proxy and CA path. - */ - struct StaticCurlTransportOptions final - { - - /** - * @brief Default Maximum time in seconds that you allow the connection phase to the server to - * take. - * - */ - AZ_CORE_DLLEXPORT static const long DefaultConnectionTimeout = 300; - - /** - * @brief The string for the proxy is passed directly to the libcurl handle without any parsing - * - * @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; - /** - * @brief The string for the certificate authenticator is sent to libcurl handle directly. - * - * @remark The Azure SDK will not check if the path is valid or not. - * - * @remark The default is the built-in system specific path. More about this option: - * https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO.html - * - */ - std::string CAInfo; - /** - * @brief All HTTP requests will keep the connection channel open to the service. - * - * @remark The channel might be closed by the server if the server response has an error code. - * A connection won't be re-used if it is abandoned in the middle of an operation. - * operation. - * - * @remark This option is managed directly by the Azure SDK. No option is set for the curl - * handle. It is `true` by default. - */ - bool HttpKeepAlive = true; - /** - * @brief This option determines whether libcurl verifies the authenticity of the peer's - * certificate. - * - * @remark The default value is `true`. More about this option: - * https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html - * - */ - bool SslVerifyPeer = true; - - /** - * @brief Define the SSL options for the libcurl handle. - * - * @remark See more info here: https://curl.haxx.se/libcurl/c/CURLOPT_SSL_OPTIONS.html. - * The default option is all options `false`. - * - */ - 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; - - /** - * @brief Contain the maximum time in seconds that you allow the connection phase to the server - * to take. - * - * @details This only limits the connection phase, it has no impact once it has connected. - * - */ - long ConnectionTimeout = DefaultConnectionTimeout; - }; - - /** - * @brief Concrete implementation of an HTTP Transport that uses libcurl. - */ - class StaticCurlTransport final : public HttpTransport { - private: - StaticCurlTransportOptions m_options; - - public: - /** - * @brief Construct a new CurlTransport object. - * - * @param options Optional parameter to override the default options. - */ - StaticCurlTransport(StaticCurlTransportOptions const& options = StaticCurlTransportOptions()) - : m_options(options) - { - } - - /** - * @brief Implements interface to send an HTTP Request and produce an HTTP RawResponse - * - * @param request an HTTP Request to be send. - * @param context A context to control the request lifetime. - * - * @return unique ptr to an HTTP RawResponse. - */ - std::unique_ptr Send(Request& request, Context const& context) override; - }; - -}}} // namespace Azure::Core::Http diff --git a/sdk/core/azure-core/src/http/curl/static_curl.cpp b/sdk/core/azure-core/src/http/curl/static_curl.cpp index 40c722147..069527156 100644 --- a/sdk/core/azure-core/src/http/curl/static_curl.cpp +++ b/sdk/core/azure-core/src/http/curl/static_curl.cpp @@ -2,9 +2,10 @@ // SPDX-License-Identifier: MIT #include "azure/core/http/policies/policy.hpp" -#include "azure/core/http/static_curl_transport.hpp" #include "azure/core/internal/diagnostics/log.hpp" +#include "static_curl_transport.hpp" + #include #if defined(_MSC_VER) @@ -50,7 +51,7 @@ class StaticCurlImpl final : public Azure::Core::IO::BodyStream { private: CURL* m_libcurlHandle; struct curl_slist* m_headerHandle = NULL; - Azure::Core::Http::StaticCurlTransportOptions m_options; + Azure::Core::Http::CurlTransportOptions m_options; std::unique_ptr m_response = nullptr; std::vector m_responseData; std::vector m_sendBuffer; @@ -199,8 +200,8 @@ private: public: StaticCurlImpl( - Azure::Core::Http::StaticCurlTransportOptions const& options - = Azure::Core::Http::StaticCurlTransportOptions()) + Azure::Core::Http::CurlTransportOptions const& options + = Azure::Core::Http::CurlTransportOptions()) : m_options(options) { // ****************************************************************** @@ -301,7 +302,7 @@ public: } if (m_options.ConnectionTimeout - != Azure::Core::Http::StaticCurlTransportOptions::DefaultConnectionTimeout) + != Azure::Core::Http::CurlTransportOptions::DefaultConnectionTimeout) { if (!SetStaticLibcurlOption( m_libcurlHandle, CURLOPT_CONNECTTIMEOUT, m_options.ConnectionTimeout, &result)) diff --git a/sdk/core/azure-core/src/http/curl/static_curl_transport.hpp b/sdk/core/azure-core/src/http/curl/static_curl_transport.hpp new file mode 100644 index 000000000..607d56327 --- /dev/null +++ b/sdk/core/azure-core/src/http/curl/static_curl_transport.hpp @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @file + * @brief #Azure::Core::Http::HttpTransport static implementation using libcurl won't produce real + * response streams. The HTTP responses are first statically downloaded within the transport + * adapter. + * + * @remark This transport adapater is less efficient than the non-static version. Use this + * implementation where performance ( memory and time ) is not a concern. + */ + +#pragma once + +#include "azure/core/context.hpp" +#include "azure/core/http/curl_transport.hpp" +#include "azure/core/http/http.hpp" +#include "azure/core/http/transport.hpp" + +namespace Azure { namespace Core { namespace Http { + + /** + * @brief Concrete implementation of an HTTP Transport that uses libcurl. + */ + class StaticCurlTransport final : public HttpTransport { + private: + CurlTransportOptions m_options; + + public: + /** + * @brief Construct a new CurlTransport object. + * + * @param options Optional parameter to override the default options. + */ + StaticCurlTransport(CurlTransportOptions const& options = CurlTransportOptions()) + : m_options(options) + { + } + + /** + * @brief Implements interface to send an HTTP Request and produce an HTTP RawResponse + * + * @param request an HTTP Request to be send. + * @param context A context to control the request lifetime. + * + * @return unique ptr to an HTTP RawResponse. + */ + std::unique_ptr Send(Request& request, Context const& context) override; + }; + +}}} // namespace Azure::Core::Http diff --git a/sdk/core/azure-core/test/ut/transport_adapter_implementation_test.cpp b/sdk/core/azure-core/test/ut/transport_adapter_implementation_test.cpp index 9d1ee1356..d39696d24 100644 --- a/sdk/core/azure-core/test/ut/transport_adapter_implementation_test.cpp +++ b/sdk/core/azure-core/test/ut/transport_adapter_implementation_test.cpp @@ -8,7 +8,7 @@ #if defined(BUILD_CURL_HTTP_TRANSPORT_ADAPTER) #include "azure/core/http/curl_transport.hpp" -#include "azure/core/http/static_curl_transport.hpp" +#include "http/curl/static_curl_transport.hpp" #endif #if defined(BUILD_TRANSPORT_WINHTTP_ADAPTER)