20template <
typename ClassType,
typename ReturnType,
typename... Args>
24 static constexpr size_t arg_count =
sizeof...(Args);
28template <
typename ClassType,
typename ReturnType,
typename... Args>
32 static constexpr size_t arg_count =
sizeof...(Args);
36template <
typename ReturnType,
typename... Args>
40 static constexpr size_t arg_count =
sizeof...(Args);
44template <
typename Handler>
47 using Ret =
typename traits::result_type;
49 if constexpr (std::is_same_v<Ret, void> || traits::arg_count == 2) {
52 return [h = std::forward<Handler>(h)](
http::HttpRequest& req, std::shared_ptr<http::ResponseWriter> writer)
mutable {
57 return [h = std::forward<Handler>(h)](
http::HttpRequest& req, std::shared_ptr<http::ResponseWriter> writer)
mutable {
60 if constexpr (traits::arg_count == 0) {
62 }
else if constexpr (traits::arg_count == 1) {
65 static_assert(traits::arg_count <= 1,
"Magic handlers can only take 0 or 1 arguments (HttpRequest&)");
69 if constexpr (std::is_same_v<Ret, std::string>) {
71 res.
headers[
"Content-Type"] =
"text/plain";
72 }
else if constexpr (std::is_same_v<Ret, nlohmann::json>) {
74 res.
headers[
"Content-Type"] =
"application/json";
79 res.
headers[
"Content-Type"] =
"application/json";
81 writer->send(std::move(res));
a class to store JSON values
Definition json.hpp:19401
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
Definition json.hpp:20574
Represents an HTTP response to be sent to a client.
Definition HttpResponse.hpp:107
std::unordered_map< std::string, std::string, utils::CaseInsensitiveHash, utils::CaseInsensitiveEqual > headers
Definition HttpResponse.hpp:111
HttpResponse & status(HttpStatus code) &
Sets the HTTP status code of the response.
Definition HttpResponse.hpp:167
HttpResponse & send(const std::string &b) &
Sets the response body as plain text.
Definition HttpResponse.hpp:174
Definition legacy_namespaces.hpp:24
auto wrap_handler(Handler &&h) -> std::function< void(http::HttpRequest &, std::shared_ptr< http::ResponseWriter >)>
Definition HandlerWrapper.hpp:45
Represents an incoming HTTP request.
Definition HttpRequest.hpp:54
std::tuple< Args... > args_tuple
Definition HandlerWrapper.hpp:23
ReturnType result_type
Definition HandlerWrapper.hpp:22
std::tuple< Args... > args_tuple
Definition HandlerWrapper.hpp:31
ReturnType result_type
Definition HandlerWrapper.hpp:30
ReturnType result_type
Definition HandlerWrapper.hpp:38
std::tuple< Args... > args_tuple
Definition HandlerWrapper.hpp:39
Definition HandlerWrapper.hpp:17