mirror of
https://github.com/typesense/typesense.git
synced 2025-05-18 12:42:50 +08:00
Fix forwarding of delete operations.
This commit is contained in:
parent
d72351e24d
commit
8bfeeeb2ee
@ -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);
|
||||
};
|
||||
|
@ -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<AsyncIndexArg*>(data);
|
||||
std::unique_ptr<AsyncIndexArg> index_arg_guard(index_arg);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user