1 #ifndef HTTPINTERFACE_H_ 2 #define HTTPINTERFACE_H_ 12 #include "utilities/utils.h" 14 using CurlHandler = std::shared_ptr<CURL>;
18 HttpResponse(std::string body_in,
const long http_status_code_in,
19 CURLcode curl_code_in, std::string error_message_in)
20 : body(std::move(body_in)),
21 http_status_code(http_status_code_in),
22 curl_code(curl_code_in),
23 error_message(std::move(error_message_in)) {}
25 long http_status_code{0};
26 CURLcode curl_code{CURLE_OK};
27 std::string error_message;
28 bool isOk() {
return (curl_code == CURLE_OK && http_status_code >= 200 && http_status_code < 400); }
29 std::string getStatusStr() {
30 return std::to_string(curl_code) +
" " + error_message +
" HTTP " + std::to_string(http_status_code);
33 Json::Value getJson() {
return Utils::parseJSON(body); }
40 virtual HttpResponse get(
const std::string &url, int64_t maxsize) = 0;
41 virtual HttpResponse post(
const std::string &url,
const Json::Value &
data) = 0;
42 virtual HttpResponse put(
const std::string &url,
const Json::Value &data) = 0;
44 virtual HttpResponse download(
const std::string &url, curl_write_callback callback,
void *userp, curl_off_t from) = 0;
45 virtual std::future<HttpResponse> downloadAsync(
const std::string &url, curl_write_callback callback,
void *userp,
46 curl_off_t from, CurlHandler *easyp) = 0;
47 virtual void setCerts(
const std::string &ca, CryptoSource ca_source,
const std::string &cert,
48 CryptoSource cert_source,
const std::string &pkey, CryptoSource pkey_source) = 0;
49 static constexpr int64_t kNoLimit = 0;
50 static constexpr int64_t kPostRespLimit = 64 * 1024;
51 static constexpr int64_t kPutRespLimit = 64 * 1024;
54 #endif // HTTPINTERFACE_H_