27 #include <olp/core/CoreApi.h>
28 #include <olp/core/http/NetworkTypes.h>
50 : bytes_uploaded_{bytes_uploaded}, bytes_downloaded_{bytes_downloaded} {}
68 bytes_uploaded_ += other.bytes_uploaded_;
69 bytes_downloaded_ += other.bytes_downloaded_;
81 uint64_t bytes_uploaded_{0};
82 uint64_t bytes_downloaded_{0};
101 : status_(status), response_(std::move(response)) {}
111 : status_(status), response_(std::move(response)) {}
123 response_(std::move(response)),
124 headers_(std::move(headers)) {}
135 : status_(other.status_),
136 headers_(other.headers_),
137 network_statistics_(other.network_statistics_) {
138 response_ << other.response_.rdbuf();
139 if (!response_.good()) {
157 if (
this != &other) {
158 status_ = other.status_;
159 response_ = std::stringstream{};
160 response_ << other.response_.rdbuf();
161 headers_ = other.headers_;
162 network_statistics_ = other.network_statistics_;
180 response_.seekg(0, std::ios::end);
181 const auto pos = response_.tellg();
185 response_.seekg(0, std::ios::beg);
186 response_.read(
reinterpret_cast<char*
>(output.data()), output.size());
187 response_.seekg(0, std::ios::beg);
195 void GetResponse(std::string& output)
const { output = response_.str(); }
203 std::vector<unsigned char> bytes;
249 network_statistics_ = network_statistics;
258 return network_statistics_;
263 std::stringstream response_;
265 NetworkStatistics network_statistics_;
This class represents the HTTP response created from the NetworkResponse and the request body.
Definition: HttpResponse.h:89
HttpResponse(int status, std::stringstream &&response, http::Headers headers)
Creates the HttpResponse instance.
Definition: HttpResponse.h:121
HttpResponse(int status, std::string response={})
Creates the HttpResponse instance.
Definition: HttpResponse.h:100
std::stringstream & GetRawResponse()
Return the reference to the response object.
Definition: HttpResponse.h:224
const NetworkStatistics & GetNetworkStatistics() const
Get the NetworkStatistics.
Definition: HttpResponse.h:257
HttpResponse(int status, std::stringstream &&response)
Creates the HttpResponse instance.
Definition: HttpResponse.h:110
HttpResponse(const HttpResponse &other)
A copy constructor.
Definition: HttpResponse.h:134
int GetStatus() const
Return the response status.
Definition: HttpResponse.h:241
void GetResponse(std::string &output) const
Copy HttpResponse content to a string.
Definition: HttpResponse.h:195
std::string GetResponseAsString() const
Renders HttpResponse content to a string.
Definition: HttpResponse.h:213
HttpResponse & operator=(HttpResponse &&)=default
A default move assignment operator.
void GetResponse(std::vector< unsigned char > &output)
Copy HttpResponse content to a vector of unsigned chars.
Definition: HttpResponse.h:179
HttpResponse & operator=(const HttpResponse &other)
A copy assignment operator.
Definition: HttpResponse.h:156
const http::Headers & GetHeaders() const
Return the const reference to the response headers.
Definition: HttpResponse.h:231
std::vector< unsigned char > GetResponseAsBytes()
Get the response body as a vector of unsigned chars.
Definition: HttpResponse.h:202
void SetNetworkStatistics(NetworkStatistics network_statistics)
Set NetworkStatistics.
Definition: HttpResponse.h:248
HttpResponse(HttpResponse &&)=default
A default move constructor.
Network statistics with information on the outbound and inbound trafic during API calls.
Definition: HttpResponse.h:37
NetworkStatistics & operator+=(const NetworkStatistics &other)
An overloaded addition operator for accumulating statistics.
Definition: HttpResponse.h:67
NetworkStatistics(uint64_t bytes_uploaded, uint64_t bytes_downloaded)
Creates the NetworkStatistics instance.
Definition: HttpResponse.h:49
NetworkStatistics operator+(const NetworkStatistics &other) const
An overloaded addition operator for accumulating statistics.
Definition: HttpResponse.h:74
uint64_t GetBytesUploaded() const
Get the number of bytes of outbound traffic.
Definition: HttpResponse.h:57
uint64_t GetBytesDownloaded() const
Get the number of bytes of inbound traffic.
Definition: HttpResponse.h:64
@ UNKNOWN_ERROR
Internal error that can't be interpreted.
std::vector< Header > Headers
An alias for a vector of the HTTP headers.
Definition: NetworkTypes.h:140
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24