olp-cpp-sdk  1.18.1
Classes | Public Types | Public Member Functions | List of all members
olp::http::Network Class Referenceabstract

An HTTP client abstraction. More...

#include <Network.h>

Classes

struct  Statistics
 Network statistics for a specific bucket. More...
 

Public Types

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.
 

Public Member Functions

virtual SendOutcome Send (NetworkRequest request, Payload payload, Callback callback, HeaderCallback header_callback=nullptr, DataCallback data_callback=nullptr)=0
 Sends the network request. More...
 
virtual void Cancel (RequestId id)=0
 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...
 

Detailed Description

An HTTP client abstraction.

Member Function Documentation

◆ Cancel()

virtual void olp::http::Network::Cancel ( RequestId  id)
pure virtual

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.

◆ GetStatistics()

virtual Statistics olp::http::Network::GetStatistics ( uint8_t  bucket_id = 0)
virtual

Gets the statistics for a bucket.

By default, it returns the statistics for the default bucket and the ID that equals 0.

Parameters
[in]bucket_idThe bucket ID.
Returns
The statistic for the requested bucket.

◆ Send()

virtual SendOutcome olp::http::Network::Send ( NetworkRequest  request,
Payload  payload,
Callback  callback,
HeaderCallback  header_callback = nullptr,
DataCallback  data_callback = nullptr 
)
pure virtual

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.

◆ SetCurrentBucket()

virtual void olp::http::Network::SetCurrentBucket ( uint8_t  bucket_id)
virtual

Sets the current bucket statistics.

Parameters
[in]bucket_idThe bucket ID.

◆ SetDefaultHeaders()

virtual void olp::http::Network::SetDefaultHeaders ( Headers  headers)
virtual

Sets the default network headers.

Default headers are applied to each request passed to the Send method. User agents are concatenated.

Parameters
headersThe default headers.

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