1 #ifndef HTTPINTERFACE_H_ 2 #define HTTPINTERFACE_H_ 11 #include "utilities/utils.h" 14 HttpResponse(std::string body_in,
const long http_status_code_in, CURLcode curl_code_in,
15 std::string error_message_in)
16 : body(std::move(body_in)),
17 http_status_code(http_status_code_in),
18 curl_code(curl_code_in),
19 error_message(std::move(error_message_in)) {}
21 long http_status_code;
23 std::string error_message;
24 bool isOk() {
return (curl_code == CURLE_OK && http_status_code >= 200 && http_status_code < 205); }
25 Json::Value getJson() {
return Utils::parseJSON(body); }
32 virtual HttpResponse get(
const std::string &url, int64_t maxsize) = 0;
33 virtual HttpResponse post(
const std::string &url,
const Json::Value &
data) = 0;
34 virtual HttpResponse put(
const std::string &url,
const Json::Value &
data) = 0;
36 virtual HttpResponse download(
const std::string &url, curl_write_callback callback,
void *userp) = 0;
37 virtual void setCerts(
const std::string &ca, CryptoSource ca_source,
const std::string &cert,
38 CryptoSource cert_source,
const std::string &pkey, CryptoSource pkey_source) = 0;
39 static constexpr int64_t kNoLimit = 0;
40 static constexpr int64_t kPostRespLimit = 64 * 1024;
41 static constexpr int64_t kPutRespLimit = 64 * 1024;
44 #endif // HTTPINTERFACE_H_