diff --git a/include/http_client.h b/include/http_client.h index 79287105..6c047701 100644 --- a/include/http_client.h +++ b/include/http_client.h @@ -34,6 +34,8 @@ public: static long get_response(const std::string & url, std::string & response, long timeout_ms=4000); + static long delete_response(const std::string & url, std::string & response, long timeout_ms=120000); + static long post_response(const std::string & url, const std::string & body, std::string & response, long timeout_ms=4000); }; diff --git a/src/core_api.cpp b/src/core_api.cpp index 16ad9448..6ed43feb 100644 --- a/src/core_api.cpp +++ b/src/core_api.cpp @@ -609,8 +609,7 @@ bool get_replication_updates(http_req & req, http_res & res) { } bool async_write_request(void *data) { - LOG(INFO) << "async_write_request called"; - + //LOG(INFO) << "async_write_request called"; AsyncIndexArg* index_arg = static_cast(data); std::unique_ptr index_arg_guard(index_arg); diff --git a/src/http_client.cpp b/src/http_client.cpp index 46c42657..0b3458c7 100644 --- a/src/http_client.cpp +++ b/src/http_client.cpp @@ -13,6 +13,18 @@ long HttpClient::post_response(const std::string &url, const std::string &body, return perform_curl(curl); } +long HttpClient::delete_response(const std::string &url, std::string &response, long timeout_ms) { + CURL *curl = init_curl(url, response); + curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, timeout_ms); + curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); + + if(curl == nullptr) { + return 0; + } + + return perform_curl(curl); +} + long HttpClient::get_response(const std::string &url, std::string &response, long timeout_ms) { CURL *curl = init_curl(url, response); curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, timeout_ms); diff --git a/src/raft_server.cpp b/src/raft_server.cpp index 306b2f09..bafaa3f9 100644 --- a/src/raft_server.cpp +++ b/src/raft_server.cpp @@ -105,7 +105,7 @@ void ReplicationState::write(http_req* request, http_res* response) { } const std::string & leader_addr = node->leader_id().to_string(); - LOG(INFO) << "Redirecting write to leader at: " << leader_addr; + //LOG(INFO) << "Redirecting write to leader at: " << leader_addr; thread_pool->enqueue([leader_addr, request, response, this]() { auto raw_req = request->_req; @@ -120,6 +120,10 @@ void ReplicationState::write(http_req* request, http_res* response) { std::string api_res; long status = HttpClient::post_response(url, request->body, api_res); response->send(status, api_res); + } else if(request->http_method == "DELETE") { + std::string api_res; + long status = HttpClient::delete_response(url, api_res); + response->send(status, api_res); } else { const std::string& err = "Forwarding for http method not implemented: " + request->http_method; LOG(ERROR) << err;