#include <Http.hpp>
Public Member Functions | |
HTTP (std::string addr, int timeoutInMs=HTTP_TIMEOUT_MS) | |
HTTP (const HTTP &)=delete | |
Copy constructor. | |
HTTP (HTTP &&)=delete | |
Move constructor. | |
HTTP & | operator= (HTTP)=delete |
Copy assignment operator. | |
HTTP & | operator= (HTTP &&)=delete |
Move assignment operator. | |
template<typename T > | |
bool | setOption (CURLoption option, T value) |
const std::string & | getHostAddress () const |
CURLcode | sendGETRequest (const std::string &index, std::string &receivedData, HttpStatus::Code &statusCode) |
CURLcode | sendHEADRequest (const std::string &index, std::string &receivedData, HttpStatus::Code &statusCode) |
CURLcode | sendPOSTRequest (const std::string &index, const std::string &payload, std::string &receivedData, HttpStatus::Code &statusCode) |
CURLcode | sendPUTRequest (const std::string &index, const std::string &payload, std::string &receivedData, HttpStatus::Code &statusCode) |
HTTPStats | getStats () |
~HTTP () | |
Private Member Functions | |
void | setCommonFields (const std::string &fullURL, std::string &receivedData, CURLoption method) |
void | setCommonFields (const std::string &fullURL, std::string &receivedData, CURLoption method, const std::string &payload) |
CURLcode | performRequest (HttpStatus::Code &statusCode) |
Static Private Member Functions | |
static size_t | writeDataCallback (const char *contents, size_t size, size_t nmemb, std::string *userp) |
Private Attributes | |
CURL * | _curl = curl_easy_init() |
CURL handler. | |
std::string | _hostAddr |
Full path of server. | |
|
explicit |
Constructs a new HTTP object
[in] | addr | The full path to the server |
[in] | timeoutInMs | The connection timeout in milliseconds |
Definition at line 46 of file Http.cpp.
|
delete |
Copy constructor.
|
delete |
Move constructor.
HTTP::~HTTP | ( | ) |
|
inlinenodiscard |
HTTPStats HTTP::getStats | ( | ) |
Gets the statistics of the HTTP object
Definition at line 93 of file Http.cpp.
|
private |
Performs the request
[out] | statusCode | The HTTP status code (set if CURLE_OK, otherwise unchanged) |
Definition at line 23 of file Http.cpp.
CURLcode HTTP::sendGETRequest | ( | const std::string & | index, |
std::string & | receivedData, | ||
HttpStatus::Code & | statusCode ) |
Sends a GET request
[in] | index | The value to append to the server address |
[out] | receivedData | The received reply from the server |
[out] | statusCode | The HTTP status code (set if CURLE_OK, otherwise unchanged) |
Definition at line 63 of file Http.cpp.
CURLcode HTTP::sendHEADRequest | ( | const std::string & | index, |
std::string & | receivedData, | ||
HttpStatus::Code & | statusCode ) |
Sends a HEAD request
[in] | index | The value to append to the server address |
[out] | receivedData | The received reply from the server |
[out] | statusCode | The HTTP status code (set if CURLE_OK, otherwise unchanged) |
Definition at line 70 of file Http.cpp.
CURLcode HTTP::sendPOSTRequest | ( | const std::string & | index, |
const std::string & | payload, | ||
std::string & | receivedData, | ||
HttpStatus::Code & | statusCode ) |
Sends a POST request
[in] | index | The value to append to the server address |
[in] | payload | The payload to send to the server |
[out] | receivedData | The received reply from the server |
[out] | statusCode | The HTTP status code (set if CURLE_OK, otherwise unchanged) |
Definition at line 77 of file Http.cpp.
CURLcode HTTP::sendPUTRequest | ( | const std::string & | index, |
const std::string & | payload, | ||
std::string & | receivedData, | ||
HttpStatus::Code & | statusCode ) |
Sends a PUT request
[in] | index | The value to append to the server address |
[in] | payload | The payload to send to the server |
[out] | receivedData | The received reply from the server |
[out] | statusCode | The HTTP status code (set if CURLE_OK, otherwise unchanged) |
Definition at line 85 of file Http.cpp.
|
private |
Sets common fields for HTTP requests
[in] | fullURL | The full URL of the request |
[out] | receivedData | The received data from the server |
[in] | method | The HTTP method to use |
Definition at line 6 of file Http.cpp.
|
private |
Sets common fields for HTTP requests with payload
[in] | fullURL | The full URL of the request |
[out] | receivedData | The received data from the server |
[in] | method | The HTTP method to use |
[in] | payload | The payload to send to the server |
Definition at line 13 of file Http.cpp.
|
inline |
|
staticprivate |
Callback function for writing received data
[in] | contents | The received data |
[in] | size | The size of each element |
[in] | nmemb | The number of elements |
[in] | userp | User pointer to a string |
Definition at line 37 of file Http.cpp.