21#ifdef _azure_TESTING_BUILD
23namespace Azure {
namespace Core {
namespace Test {
24 class CurlConnectionPool_connectionPoolTest_Test;
25 class SdkWithLibcurl_globalCleanUp_Test;
29namespace Azure {
namespace Core {
namespace Http {
43#ifdef _azure_TESTING_BUILD
45 friend class Azure::Core::Test::CurlConnectionPool_connectionPoolTest_Test;
46 friend class Azure::Core::Test::SdkWithLibcurl_globalCleanUp_Test;
53 void ReadExpected(uint8_t expected,
Context const& context);
60 void ReadCRLF(
Context const& context);
72 enum class SessionState
83 enum class ResponseParserState
102 class ResponseBufferParser final {
108 ResponseParserState state = ResponseParserState::StatusLine;
115 std::unique_ptr<RawResponse> m_response;
121 bool m_parseCompleted =
false;
123 bool m_delimiterStartInPrevPosition =
false;
136 std::string m_internalBuffer;
150 size_t BuildStatusCode(uint8_t
const*
const buffer,
size_t const bufferSize);
163 size_t BuildHeader(uint8_t
const*
const buffer,
size_t const bufferSize);
170 ResponseBufferParser() {}
188 size_t Parse(uint8_t
const*
const buffer,
size_t const bufferSize);
195 bool IsParseCompleted()
const {
return m_parseCompleted; }
203 std::unique_ptr<RawResponse> ExtractResponse()
205 if (m_parseCompleted && m_response !=
nullptr)
207 return std::move(m_response);
221 SessionState m_sessionState = SessionState::PERFORM;
223 std::unique_ptr<CurlNetworkConnection> m_connection;
230 std::unique_ptr<RawResponse> m_response;
246 size_t m_bodyStartInBuffer = _detail::DefaultLibcurlReaderSize;
254 size_t m_innerBufferSize = _detail::DefaultLibcurlReaderSize;
256 bool m_isChunkedResponseType =
false;
267 int64_t m_contentLength = 0;
274 size_t m_chunkSize = 0;
276 size_t m_sessionTotalRead = 0;
282 bool m_connectionUpgraded =
false;
290 uint8_t m_readBuffer[_detail::DefaultLibcurlReaderSize]
301 CURLcode SendRawHttp(
Context const& context);
310 CURLcode UploadBody(
Context const& context);
321 CURLcode ReadStatusLineAndHeadersFromRawResponse(
323 bool reuseInternalBuffer =
false);
331 void ParseChunkSize(
Context const& context);
347 bool m_httpKeepAlive =
false;
355 auto eof = m_isChunkedResponseType
357 :
static_cast<size_t>(m_contentLength) == m_sessionTotalRead;
363 return eof && m_sessionState != SessionState::PERFORM;
375 bool m_keepAlive =
true;
394 inline static void SetHeader(
396 std::string
const& header);
408 std::unique_ptr<CurlNetworkConnection> connection,
410 : m_connection(std::move(connection)), m_request(request),
411 m_keepAlive(curlOptions.HttpKeepAlive), m_httpProxy(curlOptions.Proxy),
412 m_httpProxyUser(curlOptions.ProxyUsername), m_httpProxyPassword(curlOptions.ProxyPassword)
424 if (IsEOF() && m_keepAlive && !m_connectionUpgraded)
426 _detail::CurlConnectionPool::g_curlConnectionPool.MoveConnectionBackToPool(
427 std::move(m_connection), m_httpKeepAlive);
438 CURLcode
Perform(Context
const& context);
453 int64_t
Length()
const override {
return m_contentLength; }
A context is a node within a unidirectional tree that represents deadlines and key/value pairs.
Definition context.hpp:72
Stateful component that controls sending an HTTP Request with libcurl over the wire.
Definition curl_session_private.hpp:42
std::unique_ptr< CurlNetworkConnection > ExtractConnection()
Return the network connection if the server indicated that the connection is upgraded.
Definition curl.cpp:521
CurlSession(Request &request, std::unique_ptr< CurlNetworkConnection > connection, CurlTransportOptions curlOptions)
Construct a new Curl Session object. Init internal libcurl handler.
Definition curl_session_private.hpp:406
int64_t Length() const override
Implement Azure::Core::IO::BodyStream length.
Definition curl_session_private.hpp:453
CURLcode Perform(Context const &context)
Function will use the HTTP request received in constructor to perform a network call based on the HTT...
Definition curl.cpp:401
std::unique_ptr< Azure::Core::Http::RawResponse > ExtractResponse()
Moved the ownership of the HTTP RawResponse out of the session.
Definition curl.cpp:1256
After receiving and interpreting a request message, a server responds with an HTTP response message.
Definition raw_response.hpp:24
A request message from a client to a server.
Definition http.hpp:183
Used to read data to/from a service.
Definition body_stream.hpp:32
Manages an optional contained value, i.e. a value that may or may not be present.
Definition nullable.hpp:30
The curl connection pool provides the utilities for creating a new curl connection and to keep a pool...
The libcurl connection keeps the curl handle and performs the data transfer to the network.
HTTP request and response functionality.
HttpStatusCode
Defines the possible HTTP status codes.
Definition http_status_code.hpp:18
Compute the hash value for the input binary data, using SHA256, SHA384 and SHA512.
Definition azure_assert.hpp:57
Set the libcurl connection options like a proxy and CA path.
Definition curl_transport.hpp:78