9 curl_easy_setopt(
_curl, CURLOPT_URL, fullURL.c_str());
10 curl_easy_setopt(
_curl, CURLOPT_WRITEDATA,
static_cast<void *
>(&
_data->data));
11 curl_easy_setopt(
_curl, method, 1L);
17 curl_easy_setopt(
_curl, CURLOPT_POSTFIELDS, payload.c_str());
18 curl_easy_setopt(
_curl, CURLOPT_POSTFIELDSIZE_LARGE,
static_cast<curl_off_t
>(payload.size()));
19 curl_easy_setopt(
_curl, CURLOPT_URL, fullURL.c_str());
20 curl_easy_setopt(
_curl, CURLOPT_WRITEDATA,
static_cast<void *
>(&
_data->data));
21 curl_easy_setopt(
_curl, method, 1L);
27 auto status =
static_cast<long>(HttpStatus::Code::xxx_max);
28 const CURLcode retval = curl_easy_perform(
_curl);
29 if (retval == CURLE_OK)
31 curl_easy_getinfo(
_curl, CURLINFO_RESPONSE_CODE, &status);
33 statusCode =
static_cast<HttpStatus::Code
>(status);
34 receivedData =
_data->data;
46 const size_t recvSize = size * nmemb;
47 userp->append(contents, recvSize);
56 throw std::invalid_argument(
"Can't init curl context");
59 curl_easy_setopt(
_curl, CURLOPT_VERBOSE, 0L);
60 curl_easy_setopt(
_curl, CURLOPT_FOLLOWLOCATION, 1L);
61 curl_easy_setopt(
_curl, CURLOPT_TIMEOUT_MS, timeoutInMs);
62 curl_easy_setopt(
_curl, CURLOPT_CONNECTTIMEOUT_MS, timeoutInMs);
65 curl_easy_setopt(
_curl, CURLOPT_SSLENGINE_DEFAULT, 1L);
66 curl_easy_setopt(
_curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
69CURLcode
HTTP::sendGETRequest(
const std::string &index, std::string &receivedData, HttpStatus::Code &statusCode)
76CURLcode
HTTP::sendHEADRequest(
const std::string &index, std::string &receivedData, HttpStatus::Code &statusCode)
84 HttpStatus::Code &statusCode)
91CURLcode
HTTP::sendPUTRequest(
const std::string &index,
const std::string &payload, std::string &receivedData,
92 HttpStatus::Code &statusCode)
103 curl_off_t value = 0;
104 curl_easy_getinfo(
_curl, CURLINFO_SIZE_UPLOAD_T, &value);
106 curl_easy_getinfo(
_curl, CURLINFO_SIZE_DOWNLOAD_T, &value);
108 curl_easy_getinfo(
_curl, CURLINFO_HEADER_SIZE, &value);
110 curl_easy_getinfo(
_curl, CURLINFO_REQUEST_SIZE, &value);
112 curl_easy_getinfo(
_curl, CURLINFO_SPEED_UPLOAD_T, &value);
114 curl_easy_getinfo(
_curl, CURLINFO_SPEED_DOWNLOAD_T, &value);
116 curl_easy_getinfo(
_curl, CURLINFO_CONNECT_TIME_T, &value);
118 curl_easy_getinfo(
_curl, CURLINFO_NAMELOOKUP_TIME_T, &value);
120 curl_easy_getinfo(
_curl, CURLINFO_PRETRANSFER_TIME_T, &value);
122 curl_easy_getinfo(
_curl, CURLINFO_REDIRECT_TIME_T, &value);
124 curl_easy_getinfo(
_curl, CURLINFO_STARTTRANSFER_TIME_T, &value);
126 curl_easy_getinfo(
_curl, CURLINFO_TOTAL_TIME_T, &value);
CURLcode sendPUTRequest(const std::string &index, const std::string &payload, std::string &receivedData, HttpStatus::Code &statusCode)
HTTP(std::string addr, int timeoutInMs=HTTP_TIMEOUT_MS)
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 performRequest(HttpStatus::Code &statusCode, std::string &receivedData)
CURL * _curl
CURL handler.
std::unique_ptr< curlMemory > _data
Memory structure for CURL.
static size_t writeDataCallback(const char *contents, size_t size, size_t nmemb, std::string *userp)
void setCommonFields(const std::string &fullURL, CURLoption method)
CURLcode sendGETRequest(const std::string &index, std::string &receivedData, HttpStatus::Code &statusCode)
std::string _hostAddr
Full path of server.
long startTransferTime
Total processing time for starting transfer in microseconds.
size_t requestBytes
Total request size in bytes.
long uploadSpeed
Upload bandwidth in Bps.
long preTransferTime
Total processing time for pre-transfer period in microseconds.
size_t headerBytes
Total header size in bytes.
size_t uploadBytes
Total uploaded bytes.
long nameLookupTime
Total processing time for name lookup in microseconds.
long totalTime
Total processing time in microseconds.
long redirectTime
Total processing time for redirections in microseconds.
size_t downloadBytes
Total downloaded bytes.
long connectionTime
Total processing time for connection in microseconds.
long downloadSpeed
Download bandwidth in Bps.