From b8922604a64d070a68ee68445b139744522a2602 Mon Sep 17 00:00:00 2001 From: rustyx Date: Fri, 8 Feb 2019 22:35:55 +0100 Subject: [PATCH] handler can receive response as argument without request being another argument. PR #312 ukseong --- include/crow/http_response.h | 6 ++++++ include/crow/routing.h | 27 ++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/crow/http_response.h b/include/crow/http_response.h index 794017479..2e738a8a3 100644 --- a/include/crow/http_response.h +++ b/include/crow/http_response.h @@ -110,6 +110,12 @@ namespace crow } } + void end(const int &_code) + { + code = _code; + end(); + } + void end(const std::string& body_part) { body += body_part; diff --git a/include/crow/routing.h b/include/crow/routing.h index 83c43e820..edbb1b2ca 100644 --- a/include/crow/routing.h +++ b/include/crow/routing.h @@ -516,7 +516,32 @@ namespace crow template typename std::enable_if< !black_magic::CallHelper>::value && - !black_magic::CallHelper>::value, + !black_magic::CallHelper>::value && + black_magic::CallHelper>::value, + void>::type + operator()(Func&& f) { + static_assert(black_magic::CallHelper>::value || + black_magic::CallHelper>::value + , + "Handler type is mismatched with URL parameters"); + static_assert(std::is_same(), std::declval()...))>::value, + "Handler function with response argument should have void return type"); + handler_ = ( +#ifdef CROW_CAN_USE_CPP14 + [f = std::move(f)] +#else + [f] +#endif + (const crow::request& req, crow::response& res, Args ... args){ + f(res, args...); + }); + } + + template + typename std::enable_if< + !black_magic::CallHelper>::value && + !black_magic::CallHelper>::value && + !black_magic::CallHelper>::value, void>::type operator()(Func&& f) {