move the static transport adapter to private impl (#2993)

This commit is contained in:
Victor Vazquez 2021-10-28 11:49:37 -07:00 committed by GitHub
parent 08947edfc8
commit 31398df179
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 162 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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<RawResponse> Send(Request& request, Context const& context) override;
};
}}} // namespace Azure::Core::Http

View File

@ -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 <memory>
#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<RawResponse> m_response = nullptr;
std::vector<uint8_t> m_responseData;
std::vector<uint8_t> 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))

View File

@ -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<RawResponse> Send(Request& request, Context const& context) override;
};
}}} // namespace Azure::Core::Http

View File

@ -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)