2020-11-28 14:28:47 +00:00
Any middleware requires following 3 members:
2021-11-06 08:54:29 +00:00
## struct context
2020-11-28 14:28:47 +00:00
Storing data for the middleware; can be read from another middleware or handlers
2021-11-06 08:54:29 +00:00
## before_handle
2020-11-28 14:28:47 +00:00
Called before handling the request.< br >
If `res.end()` is called, the operation is halted. (`after_handle` will still be called)< br >
2 signatures:< br >
`#!cpp void before_handle(request& req, response& res, context& ctx)`
if you only need to access this middleware's context.
``` cpp
template < typename AllContext >
void before_handle(request& req, response& res, context& ctx, AllContext& all_ctx)
```
You can access other middlewares' context by calling `#!cpp all_ctx.template get<MW>()` < br >
`#!cpp ctx == all_ctx.template get<CurrentMiddleware>()`
2021-11-06 08:54:29 +00:00
## after_handle
2020-11-28 14:28:47 +00:00
Called after handling the request.< br >
`#!cpp void after_handle(request& req, response& res, context& ctx)`
``` cpp
template < typename AllContext >
void after_handle(request& req, response& res, context& ctx, AllContext& all_ctx)
```
< br > < br >
2021-11-06 08:54:29 +00:00
This was pulled from `cookie_parser.h` . Further Editing required, possibly use parts of [@ipkn's wiki page ](https://github.com/ipkn/crow/wiki/Middleware ).