From 0912ee893e4d3a048074af2fccc95949fff35176 Mon Sep 17 00:00:00 2001 From: Nitromelon Date: Mon, 13 May 2024 15:09:34 +0800 Subject: [PATCH] Fix middleware/filter refs. (#70) --- ...216\247\345\210\266\345\231\250-HttpSimpleController.md" | 2 +- ...\216\247\345\210\266\345\231\250-WebSocketController.md" | 4 ++-- ...-10-\351\205\215\347\275\256\346\226\207\344\273\266.md" | 2 +- "CHN-11-drogon_ctl\345\221\275\344\273\244.md" | 2 +- ...\221\345\210\207\351\235\242\347\274\226\347\250\213.md" | 2 +- ENG-04-1-Controller-HttpSimpleController.md | 2 +- ENG-04-3-Controller-WebSocketController.md | 4 ++-- ENG-10-Configuration-File.md | 2 +- ENG-11-drogon_ctl-Command.md | 2 +- Home.md | 6 +++--- Home.zh-CN.md | 6 +++--- _Sidebar.md | 4 ++-- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git "a/CHN-04-1-\346\216\247\345\210\266\345\231\250-HttpSimpleController.md" "b/CHN-04-1-\346\216\247\345\210\266\345\231\250-HttpSimpleController.md" index 337613e..c1ce097 100644 --- "a/CHN-04-1-\346\216\247\345\210\266\345\231\250-HttpSimpleController.md" +++ "b/CHN-04-1-\346\216\247\345\210\266\345\231\250-HttpSimpleController.md" @@ -47,7 +47,7 @@ void TestCtrl::asyncHandleHttpRequest(const HttpRequestPtr &req, 从URL路径到处理函数的路由(或称映射)由宏完成,可以用`PATH_ADD`宏添加多重路径映射,所有`PATH_ADD`语句应夹在`PATH_LIST_BEGIN`和`PATH_LIST_END`宏语句之间。 -第一个参数是映射的路径,路径后面的参数是对这个路径的约束,目前支持两种约束,一种是`HttpMethod`类型,表示该路径允许使用的Http方法,可以配置零个或多个,一种是`HttpFilter`类的名字,这种对象执行特定的过滤操作,也可以配置0个或多个,两种类型没有顺序要求,框架会处理好类型的匹配。关于Filter,请参阅[过滤器 Filter](CHN-05-过滤器)。 +第一个参数是映射的路径,路径后面的参数是对这个路径的约束,目前支持两种约束,一种是`HttpMethod`类型,表示该路径允许使用的Http方法,可以配置零个或多个,一种是`HttpFilter`类的名字,这种对象执行特定的过滤操作,也可以配置0个或多个,两种类型没有顺序要求,框架会处理好类型的匹配。关于Filter,请参阅[中间件和过滤器](CHN-05-中间件和过滤器)。 用户可以把同一个Simple Controller注册到多个路径上,也可以在同一个路径上注册多个Simple Controller通过 HTTP method 区分)。 diff --git "a/CHN-04-3-\346\216\247\345\210\266\345\231\250-WebSocketController.md" "b/CHN-04-3-\346\216\247\345\210\266\345\231\250-WebSocketController.md" index a11e2c2..c6c8ccd 100644 --- "a/CHN-04-3-\346\216\247\345\210\266\345\231\250-WebSocketController.md" +++ "b/CHN-04-3-\346\216\247\345\210\266\345\231\250-WebSocketController.md" @@ -99,7 +99,7 @@ void EchoWebsock::handleConnectionClosed(const WebSocketConnectionPtr &wsConnPtr } ``` - 首先,在这个例子中,通过`WS_PATH_ADD`宏把这个控制器注册到了`/echo`路径上,`WS_PATH_ADD`宏的用法跟之前介绍的其他控制器的宏类似,也可以注册路径并且附带若干[过滤器 Filter](CHN-05-过滤器)。由于websocket在框架中单独处理,所以它可以和前两种控制器的路径重复而不会相互影响。 + 首先,在这个例子中,通过`WS_PATH_ADD`宏把这个控制器注册到了`/echo`路径上,`WS_PATH_ADD`宏的用法跟之前介绍的其他控制器的宏类似,也可以注册路径并且附带若干[中间件和过滤器](CHN-05-中间件和过滤器)。由于websocket在框架中单独处理,所以它可以和前两种控制器的路径重复而不会相互影响。 其次,本例中三个虚函数的实现,只有handleNewMessage有实质内容,只是简单的把收到的消息通过send接口发回客户端。把这个控制器编译进框架,就可以看到效果,请各位自己试验吧。 @@ -148,4 +148,4 @@ void EchoWebsock::handleConnectionClosed(const WebSocketConnectionPtr &wsConnPtr any *getMutableContext(); ``` -# 05 [过滤器](CHN-05-过滤器) +# 05 [中间件和过滤器](CHN-05-中间件和过滤器) diff --git "a/CHN-10-\351\205\215\347\275\256\346\226\207\344\273\266.md" "b/CHN-10-\351\205\215\347\275\256\346\226\207\344\273\266.md" index aa2f4e6..25d7de4 100644 --- "a/CHN-10-\351\205\215\347\275\256\346\226\207\344\273\266.md" +++ "b/CHN-10-\351\205\215\347\275\256\346\226\207\344\273\266.md" @@ -305,7 +305,7 @@ int main() * `path`:字符串,Http路径; * `controller`:字符串,HttpSimpleController的名字; * `http_methods`:字符串数组,支持的Http方法,这个列表之外的会被过滤掉,返回405错误; - * `filters`:字符串数组,路径上的filter列表,参见[过滤器](CHN-05-过滤器); + * `filters`:字符串数组,路径上的filter列表,参见[中间件和过滤器](CHN-05-中间件和过滤器); * ### idle_connection_timeout空闲连接超时控制 diff --git "a/CHN-11-drogon_ctl\345\221\275\344\273\244.md" "b/CHN-11-drogon_ctl\345\221\275\344\273\244.md" index 08b6805..7697567 100644 --- "a/CHN-11-drogon_ctl\345\221\275\344\273\244.md" +++ "b/CHN-11-drogon_ctl\345\221\275\344\273\244.md" @@ -97,7 +97,7 @@ drogon_ctl create model //create model classes in model_path * #### 过滤器创建 - `dg_ctl create filter`命令用于帮助用户创建过滤器的源文件,参见[过滤器](CHN-05-过滤器)一节。 + `dg_ctl create filter`命令用于帮助用户创建过滤器的源文件,参见[中间件和过滤器](CHN-05-中间件和过滤器)一节。 ```shell dg_ctl create filter LoginFilter diff --git "a/CHN-12-AOP\351\235\242\345\220\221\345\210\207\351\235\242\347\274\226\347\250\213.md" "b/CHN-12-AOP\351\235\242\345\220\221\345\210\207\351\235\242\347\274\226\347\250\213.md" index 44a059d..890950f 100644 --- "a/CHN-12-AOP\351\235\242\345\220\221\345\210\207\351\235\242\347\274\226\347\250\213.md" +++ "b/CHN-12-AOP\351\235\242\345\220\221\345\210\207\351\235\242\347\274\226\347\250\213.md" @@ -15,7 +15,7 @@ Drogon提供了7个插入点供用户使用,当应用程序运行至插入点 * HttpResponseCreation: 注册到这个插入点上的处理程序会在每个HTTP Response对象创建时运行,Advice的调用类型是`void(const HttpResponsePtr &)`,其中的参数就是新创建的对象,用户可以在这个处理程序中对所有Response进行一些统一的操作,比如添加某个特殊的header等,这个插入点会影响所有的Response,包括404或任何drogon内部产生的错误响应,也包括应用产生的所有响应。注册的接口是`registerHttpResponseCreationAdvice`; * Sync: 这个插入点的位置在Http请求处理的最前端,用户可以在这里通过返回一个非空的Response对象来拦截这个请求,Advice调用类型是`HttpRequestPtr(const HttpRequestPtr &)`,注册接口是`registerSyncAdvice`; -* Pre-Routing: 这个插入点的位置在框架为客户端的请求寻找相应的处理器之前,Advice的调用类型有两个,`void(const HttpRequestPtr &,AdviceCallback &&,AdviceChainCallback &&)`和`void(const HttpRequestPtr &)`, 前一个和Filter的doFilter方法的调用类型完全一致,实际上,它们的运行方式也是一样的(请参考[过滤器](CHN-05-过滤器)),用户可以通过这种Advice拦截客户端请求或者让它通过,后一种调用类型没有拦截能力,不过消耗更低,如果用户不打算拦截,请选择这种 Advice 注册。注册的接口是`registerPreRoutingAdvice`; +* Pre-Routing: 这个插入点的位置在框架为客户端的请求寻找相应的处理器之前,Advice的调用类型有两个,`void(const HttpRequestPtr &,AdviceCallback &&,AdviceChainCallback &&)`和`void(const HttpRequestPtr &)`, 前一个和Filter的doFilter方法的调用类型完全一致,实际上,它们的运行方式也是一样的(请参考[中间件和过滤器](CHN-05-中间件和过滤器)),用户可以通过这种Advice拦截客户端请求或者让它通过,后一种调用类型没有拦截能力,不过消耗更低,如果用户不打算拦截,请选择这种 Advice 注册。注册的接口是`registerPreRoutingAdvice`; * Post-Routing: 这个插入点的位置在找到处理器之后和HTTP方法检测及过滤器处理之前,Advice的调用类型和上个插入点一致,注册接口是`registerPostRoutingAdvice`; * Pre-Handling: 这个插入点的位置在通过了所有过滤器之后和处理器处理之前,Advice的调用类型和上个插入点一致,注册接口是`registerPreHandlingAdvice`; * Post-Handling: 这个插入点的位置在处理器处理完成生成Response之后和发送给客户端之前,Advice的调用类型是`oid(const HttpRequestPtr &, const HttpResponsePtr &)`,注册接口是`registerPostHandlingAdvice`; diff --git a/ENG-04-1-Controller-HttpSimpleController.md b/ENG-04-1-Controller-HttpSimpleController.md index 1631afe..0ed285d 100644 --- a/ENG-04-1-Controller-HttpSimpleController.md +++ b/ENG-04-1-Controller-HttpSimpleController.md @@ -47,7 +47,7 @@ Each HttpSimpleController class can only define one Http request handler, and it The route (or called mapping) from the URL path to the handler is done by a macro. You could add multipath mappings with the `PATH_ADD` macro. All `PATH_ADD` statements should be set between the `PATH_LIST_BEGIN` and `PATH_LIST_END` macro statements. -The first parameter is the path to be mapped, and parameters beyond the path are constraints on this path. Currently, two types of constraints are supported. One is the `HttpMethod` enum Type, which means the Http method allowed. The other type is the name of the `HttpFilter` class. One can configure any number of these two types of constraints, and there are no order requirements for them. For Filter, please refer to [Filter](ENG-05-Filter). +The first parameter is the path to be mapped, and parameters beyond the path are constraints on this path. Currently, two types of constraints are supported. One is the `HttpMethod` enum Type, which means the Http method allowed. The other type is the name of the `HttpFilter` class. One can configure any number of these two types of constraints, and there are no order requirements for them. For Filter, please refer to [Middleware and Filter](ENG-05-Middleware-and-Filter). Users can register the same Simple Controller to multiple paths, or register multiple Simple Controllers on the same path (using different HTTP methods). diff --git a/ENG-04-3-Controller-WebSocketController.md b/ENG-04-3-Controller-WebSocketController.md index fa907da..f002c18 100644 --- a/ENG-04-3-Controller-WebSocketController.md +++ b/ENG-04-3-Controller-WebSocketController.md @@ -100,7 +100,7 @@ void EchoWebsock::handleConnectionClosed(const WebSocketConnectionPtr &wsConnPtr } ``` - First, in this example, the controller is registered to the `/echo` path via the `WS_PATH_ADD` macro. The usage of the `WS_PATH_ADD` macro is similar to the macros of other controllers introduced earlier. One can also register the path with several [Filters](ENG-05-Filter). Since websocket is handled separately in the framework, it can be repeated with the paths of the first two controllers(`HttpSimpleController` and `HttpApiController`) without affecting each other. + First, in this example, the controller is registered to the `/echo` path via the `WS_PATH_ADD` macro. The usage of the `WS_PATH_ADD` macro is similar to the macros of other controllers introduced earlier. One can also register the path with several [Filters](ENG-05-Middleware-and-Filter). Since websocket is handled separately in the framework, it can be repeated with the paths of the first two controllers(`HttpSimpleController` and `HttpApiController`) without affecting each other. Secondly, in the implementation of the three virtual functions in this example, only the handleNewMessage has the substance, but simply sends the received message back to the client through the send interface.Compile this controller into the framework, you can see the effect, please test it yourself. @@ -150,4 +150,4 @@ void EchoWebsock::handleConnectionClosed(const WebSocketConnectionPtr &wsConnPtr any *getMutableContext(); ``` -# 05 [Filter](ENG-05-Filter) +# 05 [Middleware and Filter](ENG-05-Middleware-and-Filter) diff --git a/ENG-10-Configuration-File.md b/ENG-10-Configuration-File.md index 87999d9..04449d5 100644 --- a/ENG-10-Configuration-File.md +++ b/ENG-10-Configuration-File.md @@ -305,7 +305,7 @@ After commenting out a configuration option, the framework initializes it with d - `path`:String, Http path; - `controller`:String, the name of the HttpSimpleController; - `http_methods`:An array of strings representing the supported Http methods. Requests outside this list will be filtered out, returning a 405 error. - - `filters`:String array, list of filters on the path, see [Filter](ENG-05-Filter); + - `filters`:String array, list of filters on the path, see [Middleware and Filter](ENG-05-Middleware-and-Filter); - ### Idle connection timeout control diff --git a/ENG-11-drogon_ctl-Command.md b/ENG-11-drogon_ctl-Command.md index 1c70acc..72b3681 100644 --- a/ENG-11-drogon_ctl-Command.md +++ b/ENG-11-drogon_ctl-Command.md @@ -95,7 +95,7 @@ drogon_ctl create model //create model classes in model_path - #### Filter creation - The `dg_ctl create filter` command is used to help the user create the source files for filters, see the [Filter](ENG-05-Filter) section. + The `dg_ctl create filter` command is used to help the user create the source files for filters, see the [Middleware and Filter](ENG-05-Middleware-and-Filter) section. ```shell dg_ctl create filter LoginFilter diff --git a/Home.md b/Home.md index 384d021..c8c054e 100644 --- a/Home.md +++ b/Home.md @@ -36,9 +36,9 @@ * [WebSocketController](ENG-04-3-Controller-WebSocketController) * [Path Mapping](ENG-04-3-Controller-WebSocketController#Path-Mapping) * [Interface](ENG-04-3-Controller-WebSocketController#Interface) -* [Filter](ENG-05-Filter) - * [Build-in Filter](ENG-05-Filter#Build-in-Filter) - * [Custom Filter](ENG-05-Filter#Custom-Filter) +* [Middleware and Filter](ENG-05-Middleware-and-Filter) + * [Build-in Middleware/Filter](ENG-05-Middleware-and-Filter#Built-in-Middleware/Filter) + * [Custom Middleware/Filter](ENG-05-Middleware-and-Filter#Custom-Middleware/Filter) * [View](ENG-06-View) * [Drogon's CSP](ENG-06-View#Drogon's-CSP) * [Automated processing of csp files](ENG-06-View#Automated-processing-of-csp-files) diff --git a/Home.zh-CN.md b/Home.zh-CN.md index 3b438ad..688f66c 100644 --- a/Home.zh-CN.md +++ b/Home.zh-CN.md @@ -37,9 +37,9 @@ * [WebSocketController](CHN-04-3-控制器-WebSocketController) * [路径映射](CHN-04-3-控制器-WebSocketController#路径映射) * [接口](CHN-04-3-控制器-WebSocketController#接口) -* [过滤器](CHN-05-过滤器) - * [内置过滤器](CHN-05-过滤器#内置过滤器) - * [自定义过滤器](CHN-05-过滤器#自定义过滤器) +* [中间件和过滤器](CHN-05-中间件和过滤器) + * [内置中间件/过滤器](CHN-05-中间件和过滤器#内置中间件/过滤器) + * [自定义中间件/过滤器](CHN-05-中间件和过滤器#自定义中间件/过滤器) * [视图](CHN-06-视图) * [Drogon的csp](CHN-06-视图#Drogon的csp) * [csp文件的自动化处理](CHN-06-视图#csp文件的自动化处理) diff --git a/_Sidebar.md b/_Sidebar.md index 60bd1ae..298ec0b 100644 --- a/_Sidebar.md +++ b/_Sidebar.md @@ -37,7 +37,7 @@ * [WebSocketController](ENG-04-3-Controller-WebSocketController) * [Path Mapping](ENG-04-3-Controller-WebSocketController#Path-Mapping) * [Interface](ENG-04-3-Controller-WebSocketController#Interface) -* [Filter](ENG-05-Filter) +* [Middleware and Filter](ENG-05-Middleware-and-Filter) * [Build-in Filter](ENG-05-Filter#Build-in-Filter) * [Custom Filter](ENG-05-Filter#Custom-Filter) * [View](ENG-06-View) @@ -117,7 +117,7 @@ * [WebSocketController](CHN-04-3-控制器-WebSocketController) * [路径映射](CHN-04-3-控制器-WebSocketController#路径映射) * [接口](CHN-04-3-控制器-WebSocketController#接口) -* [过滤器](CHN-05-过滤器) +* [中间件和过滤器](CHN-05-中间件和过滤器) * [内置过滤器](CHN-05-过滤器#内置过滤器) * [自定义过滤器](CHN-05-过滤器#自定义过滤器) * [视图](CHN-06-视图)