olp-cpp-sdk  1.22.0
Public Member Functions | List of all members
olp::http::HarCaptureAdapter Class Referencefinal

A network adapter that captures HTTP requests and responses, generating a HAR (HTTP Archive) file. More...

#include <HarCaptureAdapter.h>

Inheritance diagram for olp::http::HarCaptureAdapter:
Inheritance graph
[legend]
Collaboration diagram for olp::http::HarCaptureAdapter:
Collaboration graph
[legend]

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...
 
- Public Member Functions inherited from olp::http::Network
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

- Public Types inherited from olp::http::Network
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.
 

Detailed Description

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.

Note
Request timings are only available when Curl is used.
The HAR file is produced when the instance is destroyed.

Features:

Example Usage:

auto network = std::make_shared<HarCaptureAdapter>(network, "/tmp/out.har");

Constructor & Destructor Documentation

◆ HarCaptureAdapter()

olp::http::HarCaptureAdapter::HarCaptureAdapter ( std::shared_ptr< Network network,
std::string  har_out_path 
)

Constructs a HarCaptureAdapter instance.

Parameters
networkThe underlying network implementation to forward requests to.
har_out_pathThe file path where the HAR (HTTP Archive) file will be saved.

Member Function Documentation

◆ Cancel()

void olp::http::HarCaptureAdapter::Cancel ( RequestId  id)
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:

auto response =
http::NetworkResponse()
.WithRequestId(id)
.WithBytesDownloaded(download_bytes)
.WithBytesUploaded(upload_bytes)
.WithStatus(static_cast<int>(http::ErrorCode::CANCELLED_ERROR))
.WithError("Cancelled");
Note
If the provided RequestId does not match any pending requests, no operations will be performed, and no callbacks will be called.
Parameters
[in]idThe unique ID of the request that you want to cancel.

Implements olp::http::Network.

◆ Send()

SendOutcome olp::http::HarCaptureAdapter::Send ( NetworkRequest  request,
Payload  payload,
Callback  callback,
HeaderCallback  header_callback,
DataCallback  data_callback 
)
overridevirtual

Sends the network request.

Parameters
[in]requestThe request that is sent.
[in]payloadThe stream used to store the response payload data.
[in]callbackThe 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_callbackThe callback that is called when an HTTP header is received. Each HTTP header entry results in a callback.
[in]data_callbackThe callback that is called when a chunk of data is received. You can trigger triggered multiple times before the final Callback call.
Returns
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.


The documentation for this class was generated from the following file: