You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/03/23 00:40:21 UTC

[apisix] branch master updated: ci: should check ngx.redirect & stream plugins (#6684)

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 2f359b4  ci: should check ngx.redirect & stream plugins (#6684)
2f359b4 is described below

commit 2f359b4c0d7dee2c6dc703a6f4a71b0666191bae
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Wed Mar 23 08:40:13 2022 +0800

    ci: should check ngx.redirect & stream plugins (#6684)
---
 docs/en/latest/plugin-develop.md | 2 +-
 docs/zh/latest/plugin-develop.md | 2 +-
 utils/check-plugins-code.sh      | 9 +++++++++
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/docs/en/latest/plugin-develop.md b/docs/en/latest/plugin-develop.md
index c7767e6..0273c20 100644
--- a/docs/en/latest/plugin-develop.md
+++ b/docs/en/latest/plugin-develop.md
@@ -308,7 +308,7 @@ function _M.log(conf, ctx)
 end
 ```
 
-**Note : we can't invoke `ngx.exit` or `core.respond.exit` in rewrite phase and access phase. if need to exit, just return the status and body, the plugin engine will make the exit happen with the returned status and body. [example](https://github.com/apache/apisix/blob/35269581e21473e1a27b11cceca6f773cad0192a/apisix/plugins/limit-count.lua#L177)**
+**Note : we can't invoke `ngx.exit`, `ngx.redirect` or `core.respond.exit` in rewrite phase and access phase. if need to exit, just return the status and body, the plugin engine will make the exit happen with the returned status and body. [example](https://github.com/apache/apisix/blob/35269581e21473e1a27b11cceca6f773cad0192a/apisix/plugins/limit-count.lua#L177)**
 
 ### extra phase
 
diff --git a/docs/zh/latest/plugin-develop.md b/docs/zh/latest/plugin-develop.md
index 3c5d612..09234fc 100644
--- a/docs/zh/latest/plugin-develop.md
+++ b/docs/zh/latest/plugin-develop.md
@@ -271,7 +271,7 @@ end
 
 根据业务功能,确定你的插件需要在哪个阶段执行。 key-auth 是一个认证插件,所以需要在 rewrite 阶段执行。在 APISIX,只有认证逻辑可以在 rewrite 阶段里面完成,其他需要在代理到上游之前执行的逻辑都是在 access 阶段完成的。
 
-**注意:我们不能在 rewrite 和 access 阶段调用 `ngx.exit` 或者 `core.respond.exit`。如果确实需要退出,只需要 return 状态码和正文,插件引擎将使用返回的状态码和正文进行退出。[例子](https://github.com/apache/apisix/blob/35269581e21473e1a27b11cceca6f773cad0192a/apisix/plugins/limit-count.lua#L177)**
+**注意:我们不能在 rewrite 和 access 阶段调用 `ngx.exit`、`ngx.redirect` 或者 `core.respond.exit`。如果确实需要退出,只需要 return 状态码和正文,插件引擎将使用返回的状态码和正文进行退出。[例子](https://github.com/apache/apisix/blob/35269581e21473e1a27b11cceca6f773cad0192a/apisix/plugins/limit-count.lua#L177)**
 
 ### APISIX 的自定义阶段
 
diff --git a/utils/check-plugins-code.sh b/utils/check-plugins-code.sh
index 910962c..dde36bf 100755
--- a/utils/check-plugins-code.sh
+++ b/utils/check-plugins-code.sh
@@ -26,6 +26,7 @@ checkfunc () {
     file=$2
     [[ $funccontent =~ "core.response.exit" ]] && echo -e ${RED}${file}${NC} && echo "    can't exit in rewrite or access phase!" && ((hit++))
     [[ $funccontent =~ "ngx.exit" ]] && echo -e ${RED}${file}${NC} && echo "    can't exit in rewrite or access phase!" && ((hit++))
+    [[ $funccontent =~ "ngx.redirect" ]] && echo -e ${RED}${file}${NC} && echo "    can't call ngx.redirect in rewrite or access phase!" && ((hit++))
 }
 
 
@@ -51,6 +52,14 @@ do
         filtercode "$content" "$file"
     fi
 done
+for file in apisix/stream/plugins/*.lua
+do
+    if test -f $file
+    then
+        content=$(cat $file)
+        filtercode "$content" "$file"
+    fi
+done
 
 if (($hit>0))
 then