olp-cpp-sdk
1.22.0
|
A network adapter that captures HTTP requests and responses, generating a HAR (HTTP Archive) file. More...
#include <HarCaptureAdapter.h>
Public Member Functions | |
HarCaptureAdapter (std::shared_ptr< Network > network, std::string har_out_path) | |
Constructs a HarCaptureAdapter instance. More... | |
SendOutcome | Send (NetworkRequest request, Payload payload, Callback callback, HeaderCallback header_callback, DataCallback data_callback) override |
Sends the network request. More... | |
void | Cancel (RequestId id) override |
Cancels the request associated with the given RequestId . More... | |
![]() | |
virtual void | SetDefaultHeaders (Headers headers) |
Sets the default network headers. More... | |
virtual void | SetCurrentBucket (uint8_t bucket_id) |
Sets the current bucket statistics. More... | |
virtual Statistics | GetStatistics (uint8_t bucket_id=0) |
Gets the statistics for a bucket. More... | |
Additional Inherited Members | |
![]() | |
using | Callback = std::function< void(NetworkResponse response)> |
The callback that is called when the request is processed or canceled. | |
using | HeaderCallback = std::function< void(std::string key, std::string value)> |
The callback that is called when a header is received. | |
using | DataCallback = std::function< void(const std::uint8_t *data, std::uint64_t offset, std::size_t length)> |
The callback that is called when a chunk of data is received. | |
using | Payload = std::shared_ptr< std::ostream > |
The request and response payload type. | |
A network adapter that captures HTTP requests and responses, generating a HAR (HTTP Archive) file.
HarCaptureAdapter implements the olp::http::Network interface, intercepting network traffic for debugging, logging, and analysis. It records request metadata, headers, and response details, allowing developers to inspect network interactions in HAR format.
Features:
Example Usage:
olp::http::HarCaptureAdapter::HarCaptureAdapter | ( | std::shared_ptr< Network > | network, |
std::string | har_out_path | ||
) |
Constructs a HarCaptureAdapter instance.
network | The underlying network implementation to forward requests to. |
har_out_path | The file path where the HAR (HTTP Archive) file will be saved. |
|
overridevirtual |
Cancels the request associated with the given RequestId
.
When the request is canceled, the user receives a final callback with an appropriate NetworkResponse
marked as canceled as illustrated in the following code snippet:
RequestId
does not match any pending requests, no operations will be performed, and no callbacks will be called.[in] | id | The unique ID of the request that you want to cancel. |
Implements olp::http::Network.
|
overridevirtual |
Sends the network request.
[in] | request | The request that is sent. |
[in] | payload | The stream used to store the response payload data. |
[in] | callback | The callback that is called when the request is fully processed or canceled. After this call, no more callbacks are triggered, and you can consider the request as done. |
[in] | header_callback | The callback that is called when an HTTP header is received. Each HTTP header entry results in a callback. |
[in] | data_callback | The callback that is called when a chunk of data is received. You can trigger triggered multiple times before the final Callback call. |
SendOutcome
that represents either a valid RequestId
as the unique request identifier or an ErrorCode
in case of failure. In case of failure, no callbacks are triggered. Implements olp::http::Network.