介绍了Crow中关于插件的使用,其实除了这种通用插件外,Crow还提供了为个别路由使用的局部插件。
先看例子:
//examples/example_middleware.cpp
struct SecretContentGuard : crow::ILocalMiddleware
{
struct context
{};
void before_handle(crow::request& /*req*/, crow::response& res, context& /*ctx*/)
{
// A request can be aborted prematurely
res.write("SECRET!");
res.code = 403;
res.end();
}
void after_handle(crow::request& /*req*/, crow::response& /*res*/, context& /*ctx*/)
{}
};
int main()
{
// ALL middleware (including per handler) is listed
crow::App<RequestLogger, SecretContentGuard, RequestAppend> app;
CROW_ROUTE(app, "/secret")
// Enable SecretContentGu