recieve response without request being another argument in handle

This commit is contained in:
ayaankhan98 2020-12-01 11:50:46 +05:30
parent b140cdf58b
commit a7c74c6327
4 changed files with 36 additions and 7 deletions

View File

@ -13,12 +13,11 @@ struct ExampleMiddleware
{ {
std::string message; std::string message;
ExampleMiddleware() ExampleMiddleware() : message(std::string("foo"))
{ {
message = "foo";
} }
void setMessage(std::string newMsg) void setMessage(const std::string &newMsg)
{ {
message = newMsg; message = newMsg;
} }

View File

@ -13,12 +13,11 @@ struct ExampleMiddleware
{ {
std::string message; std::string message;
ExampleMiddleware() ExampleMiddleware() : message(std::string("foo"))
{ {
message = "foo";
} }
void setMessage(std::string newMsg) void setMessage(const std::string &newMsg)
{ {
message = newMsg; message = newMsg;
} }

View File

@ -124,6 +124,11 @@ namespace crow
} }
} }
void end(const int& _code) {
code = _code;
end();
}
/// Same as end() except it adds a body part right before ending. /// Same as end() except it adds a body part right before ending.
void end(const std::string& body_part) void end(const std::string& body_part)
{ {

View File

@ -516,7 +516,33 @@ namespace crow
template <typename Func> template <typename Func>
typename std::enable_if< typename std::enable_if<
!black_magic::CallHelper<Func, black_magic::S<Args...>>::value && !black_magic::CallHelper<Func, black_magic::S<Args...>>::value &&
!black_magic::CallHelper<Func, black_magic::S<crow::request, Args...>>::value, !black_magic::CallHelper<Func, black_magic::S<crow::request, Args...>>::value &&
black_magic::CallHelper<Func, black_magic::S<crow::response&, Args...>>::value,
void>::type
operator()(Func&& f)
{
static_assert(black_magic::CallHelper<Func, black_magic::S<Args...>>::value ||
black_magic::CallHelper<Func, black_magic::S<crow::response&, Args...>>::value
,
"Handle type is mismatched with URL parameters");
static_assert(std::is_same<void, decltype(f(std::declval<crow::response&>(), std::declval<Args>()...))>::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 Func>
typename std::enable_if<
!black_magic::CallHelper<Func, black_magic::S<Args...>>::value&&
!black_magic::CallHelper<Func, black_magic::S<crow::request, Args...>>::value &&
!black_magic::CallHelper<Func, black_magic::S<crow::response, Args...>>::value,
void>::type void>::type
operator()(Func&& f) operator()(Func&& f)
{ {