Fix nonempty completion handler before middleware call

This commit is contained in:
Vladislav Oleshko 2022-02-08 21:15:25 +03:00
parent 80bc1cf00a
commit 0b1eb12f60

View File

@ -269,13 +269,19 @@ namespace crow
auto& ctx = *reinterpret_cast<typename App::context_t*>(req.middleware_context);
auto& container = *reinterpret_cast<typename App::mw_container_t*>(req.middleware_container);
bool completed = middleware_call_helper<middleware_call_criteria,
0, typename App::context_t, typename App::mw_container_t>(container, req, res, ctx);
if (completed) return;
auto glob_completion_handler = std::move(res.complete_request_handler_);
auto completion_handler = [&ctx, &container, &req, &res, &glob_completion_handler] {
res.complete_request_handler_ = [] {};
middleware_call_helper<middleware_call_criteria,
0, typename App::context_t, typename App::mw_container_t>(container, req, res, ctx);
if (res.completed_)
{
glob_completion_handler();
return;
}
res.complete_request_handler_ = [&ctx, &container, &req, &res, &glob_completion_handler] {
after_handlers_call_helper<
middleware_call_criteria,
std::tuple_size<typename App::mw_container_t>::value - 1,
@ -283,7 +289,6 @@ namespace crow
typename App::mw_container_t>(container, ctx, req, res);
glob_completion_handler();
};
res.complete_request_handler_ = std::move(completion_handler);
wrapped_handler_call(req, res, f, std::forward<Args>(args)...);
}