@@ -3600,6 +3600,67 @@ TEST_CASE("catchall")
36003600 }
36013601} // catchall
36023602
3603+
3604+ TEST_CASE (" catchall_check_full_handling" )
3605+ {
3606+ struct LocalSecretMiddleware : crow::ILocalMiddleware
3607+ {
3608+ struct context {
3609+ bool before_handle_called{false };
3610+ bool after_handle_called{false };
3611+ };
3612+
3613+ void before_handle (request& /* req*/ , response& res, context& ctx)
3614+ {
3615+ ctx.before_handle_called = true ;
3616+
3617+ res.code = 403 ;
3618+ res.end ();
3619+ }
3620+
3621+ void after_handle (request& /* req*/ , response& /* res*/ , context& ctx) {
3622+ ctx.after_handle_called = true ;
3623+
3624+ }
3625+ };
3626+
3627+ App<LocalSecretMiddleware> app;
3628+ bool headers_empty=true ;
3629+ CROW_ROUTE (app, " /" )
3630+ ([]() {
3631+ return " works!" ;
3632+ });
3633+
3634+ CROW_CATCHALL_ROUTE (app) ([&headers_empty](const crow::request& req,response& res) {
3635+ headers_empty = req.headers .empty ();
3636+ res.add_header (" bla" ," bla_val" );
3637+ res.body = " bla_body" ;
3638+
3639+ });
3640+
3641+ CROW_ROUTE (app, " /secret" )
3642+ .middlewares <decltype (app), LocalSecretMiddleware>()([]() {
3643+ return " works!" ;
3644+ });
3645+
3646+ app.validate ();
3647+
3648+ auto _ = app.bindaddr (LOCALHOST_ADDRESS).port (45451 ).run_async ();
3649+ app.wait_for_server_start ();
3650+
3651+ {
3652+ // call not handled url to get response from catch_all handler
3653+ auto resp = HttpClient::request (LOCALHOST_ADDRESS, 45451 ,
3654+ " GET /catch_all\r\n\r\n " );
3655+
3656+ CHECK (resp.find (" bla" ) != std::string::npos);
3657+ CHECK (headers_empty==false );
3658+ }
3659+
3660+ app.stop ();
3661+ } // local_middleware
3662+
3663+
36033664TEST_CASE (" blueprint" )
36043665{
36053666 SimpleApp app;
0 commit comments