diff options
author | ipknHama <ipknhama@gmail.com> | 2014-09-07 01:24:45 +0900 |
---|---|---|
committer | ipknHama <ipknhama@gmail.com> | 2014-09-07 01:24:45 +0900 |
commit | c89cafa820ec02f041c3b0e52877bc321f6a1ba9 (patch) | |
tree | 8b74deacdefd07048c230cb553efe6bb4e7352e1 /include/crow.h | |
parent | daa3c820878f8e189120cf9359caf8b2359d61ca (diff) | |
download | crow-c89cafa820ec02f041c3b0e52877bc321f6a1ba9.tar.gz crow-c89cafa820ec02f041c3b0e52877bc321f6a1ba9.zip |
add Middlewares template to Crow main class, context implementation
Diffstat (limited to 'include/crow.h')
-rw-r--r-- | include/crow.h | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/include/crow.h b/include/crow.h index 55572bf..a018f31 100644 --- a/include/crow.h +++ b/include/crow.h @@ -13,6 +13,8 @@ #include "http_server.h" #include "utility.h" #include "routing.h" +#include "middleware_impl.h" +#include "http_request.h" // TEST #include <iostream> @@ -21,6 +23,7 @@ namespace crow { + template <typename ... Middlewares> class Crow { public: @@ -78,12 +81,26 @@ namespace crow router_.debug_print(); } + // middleware + using context_t = detail::context<Middlewares...>; + template <typename T> + T& get_middleware_context(request& req) + { + static_assert(black_magic::contains<T, Middlewares...>::value, "App doesn't have the specified middleware type."); + auto& ctx = *reinterpret_cast<context_t*>(req.middleware_context); + return ctx.get<T>(); + } + private: uint16_t port_ = 80; uint16_t concurrency_ = 1; + std::tuple<Middlewares...> middlewares_; + Router router_; }; - using App = Crow; + template <typename ... Middlewares> + using App = Crow<Middlewares...>; + using SimpleApp = Crow<>; }; |