An HTTP client abstraction.
More...
#include <Network.h>
|
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.
|
|
An HTTP client abstraction.
◆ 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] | id | The 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_id | The bucket ID. |
- Returns
- The statistic for the requested bucket.
◆ Send()
Sends the network request.
- Parameters
-
[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. |
- 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_id | The 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
-
headers | The default headers. |
The documentation for this class was generated from the following file:
- olp-cpp-sdk-core/include/olp/core/http/Network.h