Forward patch request to leader

This commit is contained in:
Jason Bosco 2021-01-22 16:51:57 -08:00
parent 1e1f7371f2
commit d2206168ec
3 changed files with 20 additions and 0 deletions

View File

@ -58,5 +58,8 @@ public:
static long put_response(const std::string & url, const std::string & body, std::string & response,
std::map<std::string, std::string>& res_headers, long timeout_ms=4000);
static long patch_response(const std::string & url, const std::string & body, std::string & response,
std::map<std::string, std::string>& res_headers, long timeout_ms=4000);
static void extract_response_headers(CURL* curl, std::map<std::string, std::string> &res_headers);
};

View File

@ -46,6 +46,18 @@ long HttpClient::put_response(const std::string &url, const std::string &body, s
return perform_curl(curl, res_headers);
}
long HttpClient::patch_response(const std::string &url, const std::string &body, std::string &response,
std::map<std::string, std::string>& res_headers, long timeout_ms) {
CURL *curl = init_curl(url, response);
if(curl == nullptr) {
return 500;
}
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
return perform_curl(curl, res_headers);
}
long HttpClient::delete_response(const std::string &url, std::string &response,
std::map<std::string, std::string>& res_headers, long timeout_ms) {
CURL *curl = init_curl(url, response);

View File

@ -223,6 +223,11 @@ void ReplicationState::write_to_leader(http_req *request, http_res *response) co
long status = HttpClient::delete_response(url, api_res, res_headers);
response->content_type_header = res_headers["content-type"];
response->set_body(status, api_res);
} else if(request->http_method == "PATCH") {
std::string api_res;
long status = HttpClient::patch_response(url, request->body, api_res, res_headers);
response->content_type_header = res_headers["content-type"];
response->set_body(status, api_res);
} else {
const std::string& err = "Forwarding for http method not implemented: " + request->http_method;
LOG(ERROR) << err;