mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
Add local middleware after handlers to request handler
This commit is contained in:
parent
69e9ad9c1e
commit
5d6db06706
@ -19,12 +19,20 @@ namespace crow
|
||||
template<typename Adaptor, typename Handler, typename... Middlewares>
|
||||
class Connection;
|
||||
|
||||
namespace detail {
|
||||
template<typename F, typename App, typename... Middlewares>
|
||||
struct handler_middleware_wrapper;
|
||||
} // namespace detail
|
||||
|
||||
/// HTTP response
|
||||
struct response
|
||||
{
|
||||
template<typename Adaptor, typename Handler, typename... Middlewares>
|
||||
friend class crow::Connection;
|
||||
|
||||
template<typename F, typename App, typename... Middlewares>
|
||||
friend struct crow::detail::handler_middleware_wrapper;
|
||||
|
||||
int code{200}; ///< The Status code for the response.
|
||||
std::string body; ///< The actual payload containing the response data.
|
||||
ci_map headers; ///< HTTP headers.
|
||||
|
@ -274,13 +274,18 @@ namespace crow
|
||||
|
||||
if (completed) return;
|
||||
|
||||
wrapped_handler_call(req, res, f, std::forward<Args>(args)...);
|
||||
auto glob_completion_handler = std::move(res.complete_request_handler_);
|
||||
auto completion_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,
|
||||
typename App::context_t,
|
||||
typename App::mw_container_t>(container, ctx, req, res);
|
||||
glob_completion_handler();
|
||||
};
|
||||
res.complete_request_handler_ = std::move(completion_handler);
|
||||
|
||||
after_handlers_call_helper<
|
||||
middleware_call_criteria,
|
||||
std::tuple_size<typename App::mw_container_t>::value - 1,
|
||||
typename App::context_t,
|
||||
typename App::mw_container_t>(container, ctx, req, res);
|
||||
wrapped_handler_call(req, res, f, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
F f;
|
||||
|
Loading…
Reference in New Issue
Block a user