![]() |
Kurlyk
|
Manages asynchronous HTTP requests, including handling responses, retries, and error processing. More...
#include <HttpRequestHandler.hpp>
Public Member Functions | |
| HttpRequestHandler (std::unique_ptr< HttpRequestContext > context) | |
| Constructs an HttpRequestHandler with the specified request context. | |
| ~HttpRequestHandler () | |
| Destructor for HttpRequestHandler, handling cleanup of CURL and headers. | |
| bool | handle_curl_message (CURLMsg *message) |
| Processes a CURL message and determines if a callback should be invoked. | |
| CURL * | get_curl () noexcept |
| Retrieves the CURL handle associated with this request. | |
| std::unique_ptr< HttpRequestContext > | get_request_context () |
| Returns the unique pointer to the HttpRequestContext object. | |
| uint64_t | get_request_id () |
| Retrieves the unique ID of the HTTP request. | |
| uint64_t | get_group_id () |
| Retrieves the group ID of the HTTP request. | |
| bool | is_done () const noexcept |
| Checks whether this request has already received its final callback. | |
| void | mark_done () noexcept |
| Marks the request as done without invoking a callback. | |
| void | cancel () |
| Marks the request as cancelled. | |
Static Public Member Functions | |
| static size_t | write_http_response_body (char *data, size_t size, size_t nmemb, void *userdata) |
| Processes body data received from server and appends it to response content. | |
| static size_t | parse_http_response_header (char *buffer, size_t size, size_t nitems, void *userdata) |
| Parses and stores response headers in the Headers container. | |
Private Member Functions | |
| void | init_curl () |
| Initializes CURL options for the request, setting headers, method, SSL, timeouts, and other parameters. | |
| size_t | write_response_body (const char *data, size_t total_size) |
| Stores received body data and emits a streaming chunk when enabled. | |
| void | emit_stream_chunk (const char *data, size_t total_size) |
| Invokes the response callback with an intermediate body chunk. | |
| void | fill_response_timings () |
| void | set_ssl_options (const HttpRequest &request) |
| Sets SSL options such as cert, key, and CA file. | |
| void | set_request_options (const HttpRequest &request) |
| Sets general options such as headers, cookies, and proxy. | |
| void | set_custom_headers (const HttpRequest &request) |
| Appends custom headers to the request if provided. | |
| void | set_proxy_options (const HttpRequest &request) |
| Configures proxy options if set in the request. | |
| void | set_cookie_options (const HttpRequest &request) |
| Sets cookie options if cookies are specified in the request. | |
| void | set_request_body (const HttpRequest &request) |
| Sets request body content for applicable HTTP methods. | |
| const char * | get_ca_file_path () const |
| Gets the full path to the CA certificate file. | |
Private Attributes | |
| std::unique_ptr< HttpRequestContext > | m_request_context |
| Context for the current request. | |
| std::unique_ptr< HttpResponse > | m_response |
| Response object. | |
| CURL * | m_curl = nullptr |
| CURL handle for the request. | |
| struct curl_slist * | m_headers = nullptr |
| CURL headers list. | |
| char | m_error_buffer [CURL_ERROR_SIZE] |
| Buffer for CURL error messages. | |
| bool | m_callback_called = false |
| Indicates if the callback was called. | |
| bool | m_has_stream_chunk = false |
| Indicates if a streaming body chunk was emitted. | |
| bool | m_done = false |
| Indicates if the request has received its final callback. | |
| std::string | m_ca_file |
| Cached CA file path. | |
Manages asynchronous HTTP requests, including handling responses, retries, and error processing.
Definition at line 12 of file HttpRequestHandler.hpp.
|
inlineexplicit |
Constructs an HttpRequestHandler with the specified request context.
| context | Unique pointer to the HttpRequestContext object. |
Definition at line 17 of file HttpRequestHandler.hpp.
|
inline |
Destructor for HttpRequestHandler, handling cleanup of CURL and headers.
If the callback has not been called yet, this indicates the request was incomplete, and an error response is passed to the callback.
Definition at line 32 of file HttpRequestHandler.hpp.
|
inline |
Marks the request as cancelled.
Definition at line 147 of file HttpRequestHandler.hpp.
|
inlineprivate |
Invokes the response callback with an intermediate body chunk.
Definition at line 208 of file HttpRequestHandler.hpp.
|
inlineprivate |
Definition at line 244 of file HttpRequestHandler.hpp.
|
inlineprivate |
Gets the full path to the CA certificate file.
Definition at line 352 of file HttpRequestHandler.hpp.
|
inlinenoexcept |
Retrieves the CURL handle associated with this request.
Definition at line 124 of file HttpRequestHandler.hpp.
|
inline |
Retrieves the group ID of the HTTP request.
Definition at line 136 of file HttpRequestHandler.hpp.
|
inline |
Returns the unique pointer to the HttpRequestContext object.
Definition at line 128 of file HttpRequestHandler.hpp.
|
inline |
Retrieves the unique ID of the HTTP request.
Definition at line 132 of file HttpRequestHandler.hpp.
|
inline |
Processes a CURL message and determines if a callback should be invoked.
Definition at line 67 of file HttpRequestHandler.hpp.
|
inlineprivate |
Initializes CURL options for the request, setting headers, method, SSL, timeouts, and other parameters.
Definition at line 173 of file HttpRequestHandler.hpp.
|
inlinenoexcept |
Checks whether this request has already received its final callback.
Definition at line 140 of file HttpRequestHandler.hpp.
|
inlinenoexcept |
Marks the request as done without invoking a callback.
Used when the handler stays in the batch after curl removal (retry extraction).
Definition at line 144 of file HttpRequestHandler.hpp.
|
inlinestatic |
Parses and stores response headers in the Headers container.
Definition at line 55 of file HttpRequestHandler.hpp.
|
inlineprivate |
Sets cookie options if cookies are specified in the request.
Definition at line 327 of file HttpRequestHandler.hpp.
|
inlineprivate |
Appends custom headers to the request if provided.
Definition at line 292 of file HttpRequestHandler.hpp.
|
inlineprivate |
Configures proxy options if set in the request.
Definition at line 314 of file HttpRequestHandler.hpp.
|
inlineprivate |
Sets request body content for applicable HTTP methods.
Definition at line 340 of file HttpRequestHandler.hpp.
|
inlineprivate |
Sets general options such as headers, cookies, and proxy.
Definition at line 273 of file HttpRequestHandler.hpp.
|
inlineprivate |
Sets SSL options such as cert, key, and CA file.
Definition at line 254 of file HttpRequestHandler.hpp.
|
inlinestatic |
Processes body data received from server and appends it to response content.
Definition at line 47 of file HttpRequestHandler.hpp.
|
inlineprivate |
Stores received body data and emits a streaming chunk when enabled.
Definition at line 199 of file HttpRequestHandler.hpp.
|
mutableprivate |
Cached CA file path.
Definition at line 170 of file HttpRequestHandler.hpp.
|
private |
Indicates if the callback was called.
Definition at line 167 of file HttpRequestHandler.hpp.
|
private |
CURL handle for the request.
Definition at line 164 of file HttpRequestHandler.hpp.
|
private |
Indicates if the request has received its final callback.
Definition at line 169 of file HttpRequestHandler.hpp.
|
private |
Buffer for CURL error messages.
Definition at line 166 of file HttpRequestHandler.hpp.
|
private |
Indicates if a streaming body chunk was emitted.
Definition at line 168 of file HttpRequestHandler.hpp.
|
private |
CURL headers list.
Definition at line 165 of file HttpRequestHandler.hpp.
|
private |
Context for the current request.
Definition at line 162 of file HttpRequestHandler.hpp.
|
private |
Response object.
Definition at line 163 of file HttpRequestHandler.hpp.