diff --git a/examples/simple_example/api_v1_ApiTest.h b/examples/simple_example/api_v1_ApiTest.h index f7b5ef28..a5ab5d08 100755 --- a/examples/simple_example/api_v1_ApiTest.h +++ b/examples/simple_example/api_v1_ApiTest.h @@ -7,15 +7,16 @@ namespace api { class ApiTest:public drogon::HttpApiController { - METHOD_LIST_BEGIN - //use METHOD_ADD to add your custom processing function here; - METHOD_ADD(ApiTest::get,"/{2}/{1}",1,"drogon::GetFilter");//path will be /api/v1/ApiTest/get/{arg2}/{arg1} - METHOD_ADD(ApiTest::your_method_name,"/{1}/list?p2={2}",0,"drogon::GetFilter");//path will be /api/v1/ApiTest/{arg1}/list - - METHOD_LIST_END - //your declaration of processing function maybe like this: - void get(const HttpRequestPtr& req,const std::function&callback,int p1,std::string p2); - void your_method_name(const HttpRequestPtr& req,const std::function&callback,double p1,int p2) const; + public: + METHOD_LIST_BEGIN + //use METHOD_ADD to add your custom processing function here; + METHOD_ADD(ApiTest::get,"/{2}/{1}",1,"drogon::GetFilter");//path will be /api/v1/ApiTest/get/{arg2}/{arg1} + METHOD_ADD(ApiTest::your_method_name,"/{1}/list?p2={2}",0,"drogon::GetFilter");//path will be /api/v1/ApiTest/{arg1}/list + + METHOD_LIST_END + //your declaration of processing function maybe like this: + void get(const HttpRequestPtr& req,const std::function&callback,int p1,std::string p2); + void your_method_name(const HttpRequestPtr& req,const std::function&callback,double p1,int p2) const; }; } } diff --git a/examples/simple_example/main.cc b/examples/simple_example/main.cc index 18fd9c9e..8f81ae4b 100755 --- a/examples/simple_example/main.cc +++ b/examples/simple_example/main.cc @@ -47,6 +47,7 @@ namespace api { class Test:public HttpApiController { + public: METHOD_LIST_BEGIN METHOD_ADD(Test::get,"/{2}/{1}",1,"drogon::GetFilter");//path will be /api/v1/test/get/{arg2}/{arg1} METHOD_ADD(Test::list,"/{2}/info",0,"drogon::GetFilter");//path will be /api/v1/test/{arg2}/info diff --git a/lib/inc/drogon/HttpApiController.h b/lib/inc/drogon/HttpApiController.h index e219820c..91f8cf8e 100755 --- a/lib/inc/drogon/HttpApiController.h +++ b/lib/inc/drogon/HttpApiController.h @@ -21,7 +21,7 @@ #include #include -#define METHOD_LIST_BEGIN public:\ +#define METHOD_LIST_BEGIN \ static void initMethods() \ { #define METHOD_ADD(method,pattern,isMethodNameInPath,filters...) \ @@ -41,7 +41,9 @@ static void initMethods() \ #define METHOD_LIST_END \ return;\ -} +}\ +protected: + namespace drogon { template diff --git a/lib/src/HttpAppFramework.cc b/lib/src/HttpAppFramework.cc index 50484176..c7ca545a 100755 --- a/lib/src/HttpAppFramework.cc +++ b/lib/src/HttpAppFramework.cc @@ -579,6 +579,14 @@ void HttpAppFrameworkImpl::onAsyncRequest(const HttpRequestPtr& req,const std::f } } } + else{ + //No controller found + auto res=drogon::HttpResponse::notFoundResponse(); + if(needSetJsessionid) + res->addCookie("JSESSIONID",session_id); + + callback(*res); + } } else{ //No controller found