Handle premature termination of resource-limited request.

This commit is contained in:
Kishore Nallan 2023-03-10 17:07:05 +05:30
parent b5aa84f743
commit ee3ed42713
2 changed files with 9 additions and 3 deletions

View File

@ -205,17 +205,19 @@ void BatchedIndexer::run() {
std::string(magic_enum::enum_name(resource_check));
LOG(ERROR) << err_msg;
orig_res->set_422(err_msg);
orig_res->final = true;
async_req_res_t* async_req_res = new async_req_res_t(orig_req, orig_res, true);
server->get_message_dispatcher()->send_message(HttpServer::STREAM_RESPONSE_MESSAGE, async_req_res);
break;
goto end;
}
else if(route_found) {
if(skip_writes && found_rpath->handler != post_config) {
orig_res->set(422, "Skipping write.");
orig_res->final = true;
async_req_res_t* async_req_res = new async_req_res_t(orig_req, orig_res, true);
server->get_message_dispatcher()->send_message(HttpServer::STREAM_RESPONSE_MESSAGE, async_req_res);
break;
goto end;
}
async_res = found_rpath->async_res;
@ -226,6 +228,7 @@ void BatchedIndexer::run() {
LOG(ERROR) << "Raw error: " << e.what();
// bad request gets a response immediately
orig_res->set_400("Bad request.");
orig_res->final = true;
async_res = false;
}
prev_body = orig_req->body;
@ -240,10 +243,12 @@ void BatchedIndexer::run() {
}
if(!route_found) {
break;
goto end;
}
}
end:
queued_writes--;
orig_req_res.next_chunk_index++;
iter->Next();

View File

@ -202,6 +202,7 @@ void ReplicationState::write(const std::shared_ptr<http_req>& request, const std
if(config->get_skip_writes() && request->path_without_query != "/config") {
response->set_422("Skipping writes.");
response->final = true;
auto req_res = new async_req_res_t(request, response, true);
return message_dispatcher->send_message(HttpServer::STREAM_RESPONSE_MESSAGE, req_res);
}