From 6a317e8b87c26c4b53892b8463ef9d343dd04efb Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Fri, 18 Dec 2020 02:13:03 +0000 Subject: [PATCH] Move the default transport adapter assignation to the source (#1206) fixes: #1169 --- CMakeLists.txt | 2 +- cmake-modules/DefineTransportAdapter.cmake | 2 +- sdk/core/azure-core/CHANGELOG.md | 5 +++++ .../azure-core/inc/azure/core/http/policy.hpp | 20 ++++++++----------- .../azure-core/src/http/transport_policy.cpp | 13 ++++++++++++ 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 037f6c84a..d9bd0ea78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ set(AZ_ALL_LIBRARIES ON) option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" ON) option(BUILD_TRANSPORT_CURL "Build an HTTP transport implementation with CURL" OFF) option(BUILD_TRANSPORT_WINHTTP "Build an HTTP transport implementation with WIN HTTP" OFF) -option(BUILD_TRANSPORT_CUSTOM "Implementation for GetCustomHttpTransport method must be linked to the final application" OFF) +option(BUILD_TRANSPORT_CUSTOM "Implementation for AzureSdkGetCustomHttpTransport method must be linked to the final application" OFF) option(BUILD_TESTING "Build test cases" OFF) option(BUILD_CODE_COVERAGE "Build gcov targets for HTML and XML reports. Requires debug build and BUILD_TESTING" OFF) option(BUILD_DOCUMENTATION "Create HTML based API documentation (requires Doxygen)" OFF) diff --git a/cmake-modules/DefineTransportAdapter.cmake b/cmake-modules/DefineTransportAdapter.cmake index 6b0790cf2..7ccccebc0 100644 --- a/cmake-modules/DefineTransportAdapter.cmake +++ b/cmake-modules/DefineTransportAdapter.cmake @@ -7,7 +7,7 @@ # POSIX: Only CURL is acceptable. If WIN_HTTP is set, generate step will fail for user # if (BUILD_TRANSPORT_CUSTOM) - message("Using the user-defined transport adapter. Make sure `GetCustomHttpTransport` is implemented and linked.") + message("Using the user-defined transport adapter. Make sure `AzureSdkGetCustomHttpTransport` is implemented and linked.") add_compile_definitions(BUILD_TRANSPORT_CUSTOM_ADAPTER) endif() diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index 1c527f42f..54f1a05ee 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -7,6 +7,7 @@ - Added a WinHTTP-based `HttpTransport` called `WinHttpTransport` and use that as the default `TransportPolicyOptions.Transport` on Windows when sending and receiving requests and responses over the wire. - Added `Range` type to `Azure::Core::Http` namespace. - Added support for long-running operations with `Operation`. +- Added support for setting a custom transport adapter by implementing the method `std::shared_ptr ::AzureSdkGetCustomHttpTransport()`. ### Breaking Changes @@ -15,6 +16,10 @@ - Removed option `AllowBeast` from `CurlTransportSSLOptions` in `CurlTransportOptions`. - Changed default option `NoRevoke` from `CurlTransportSSLOptions` for the `CurlTransportOptions` to `true`. This disables the revocation list checking by default. +### Bug Fixes + +- Fixed for setting up the default transport adapter. + ## 1.0.0-beta.3 (2020-11-11) ### New Features diff --git a/sdk/core/azure-core/inc/azure/core/http/policy.hpp b/sdk/core/azure-core/inc/azure/core/http/policy.hpp index d70357a5e..b4fd9853d 100644 --- a/sdk/core/azure-core/inc/azure/core/http/policy.hpp +++ b/sdk/core/azure-core/inc/azure/core/http/policy.hpp @@ -15,6 +15,8 @@ #include "azure/core/logging/logging.hpp" #include "azure/core/uuid.hpp" +// Need to include the transport adapters offered by the SDK here so anyone can use them by just +// including policy.hpp #include "azure/core/http/curl/curl.hpp" #include "azure/core/http/winhttp/win_http_client.hpp" @@ -23,6 +25,10 @@ namespace Azure { namespace Core { namespace Http { + namespace Details { + std::shared_ptr GetTransportAdapter(); + } + class NextHttpPolicy; /** @@ -113,20 +119,10 @@ namespace Azure { namespace Core { namespace Http { * curl transport adapter and winhttp transport adapter on Windows. * * @remark When using a custom transport adapter, the implementation for - * `GetCustomHttpTransport` must be linked in the end-user application. + * `AzureSdkGetCustomHttpTransport` must be linked in the end-user application. * */ - - // The order of these checks is important so that WinHttp is picked over Curl on Windows, when - // both are defined. -#if defined(BUILD_TRANSPORT_CUSTOM_ADAPTER) - std::shared_ptr Transport = ::GetCustomHttpTransport(); -#elif defined(BUILD_TRANSPORT_WINHTTP_ADAPTER) - std::shared_ptr Transport - = std::make_shared(); -#else - std::shared_ptr Transport = std::make_shared(); -#endif + std::shared_ptr Transport = Details::GetTransportAdapter(); }; /** diff --git a/sdk/core/azure-core/src/http/transport_policy.cpp b/sdk/core/azure-core/src/http/transport_policy.cpp index e626b8cfc..06c625cab 100644 --- a/sdk/core/azure-core/src/http/transport_policy.cpp +++ b/sdk/core/azure-core/src/http/transport_policy.cpp @@ -6,6 +6,19 @@ using Azure::Core::Context; using namespace Azure::Core::Http; +std::shared_ptr Azure::Core::Http::Details::GetTransportAdapter() +{ + // The order of these checks is important so that WinHttp is picked over Curl on Windows, when + // both are defined. +#if defined(BUILD_TRANSPORT_CUSTOM_ADAPTER) + return ::AzureSdkGetCustomHttpTransport(); +#elif defined(BUILD_TRANSPORT_WINHTTP_ADAPTER) + return std::make_shared(); +#else + return std::make_shared(); +#endif +} + std::unique_ptr TransportPolicy::Send( Context const& ctx, Request& request,