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/06/10 02:46:44 UTC

[apisix] branch master updated: docs: add re case on response-rewrite plugin (#7197)

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 e5f7cec54 docs: add re case on response-rewrite plugin (#7197)
e5f7cec54 is described below

commit e5f7cec543a4a9994e2a98763e9a813782725eb6
Author: Zhendong Qi <88...@users.noreply.github.com>
AuthorDate: Fri Jun 10 10:46:39 2022 +0800

    docs: add re case on response-rewrite plugin (#7197)
---
 docs/en/latest/plugins/response-rewrite.md | 65 ++++++++++++++++++++++++++++++
 docs/zh/latest/plugins/response-rewrite.md | 65 ++++++++++++++++++++++++++++++
 2 files changed, 130 insertions(+)

diff --git a/docs/en/latest/plugins/response-rewrite.md b/docs/en/latest/plugins/response-rewrite.md
index 80ce66e6e..a74bea830 100644
--- a/docs/en/latest/plugins/response-rewrite.md
+++ b/docs/en/latest/plugins/response-rewrite.md
@@ -130,6 +130,71 @@ So, if you have configured the `response-rewrite` Plugin, it do a force overwrit
 
 :::
 
+The example below shows how you can replace a key in the response body. Here, the key X-Amzn-Trace-Id is replaced with X-Amzn-Trace-Id-Replace by configuring the filters attribute using regex:
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+  "plugins":{
+    "response-rewrite":{
+      "headers":{
+        "X-Server-id":3,
+        "X-Server-status":"on",
+        "X-Server-balancer_addr":"$balancer_ip:$balancer_port"
+      },
+      "filters":[
+        {
+          "regex":"X-Amzn-Trace-Id",
+          "scope":"global",
+          "replace":"X-Amzn-Trace-Id-Replace"
+        }
+      ],
+      "vars":[
+        [
+          "status",
+          "==",
+          200
+        ]
+      ]
+    }
+  },
+  "upstream":{
+    "type":"roundrobin",
+    "scheme":"https",
+    "nodes":{
+      "httpbin.org:443":1
+    }
+  },
+  "uri":"/*"
+}'
+```
+
+```shell
+curl -X GET -i  http://127.0.0.1:9080/get
+```
+
+```shell
+HTTP/1.1 200 OK
+Transfer-Encoding: chunked
+X-Server-status: on
+X-Server-balancer-addr: 34.206.80.189:443
+X-Server-id: 3
+
+{
+  "args": {},
+  "headers": {
+    "Accept": "*/*",
+    "Host": "127.0.0.1",
+    "User-Agent": "curl/7.29.0",
+    "X-Amzn-Trace-Id-Replace": "Root=1-629e0b89-1e274fdd7c23ca6e64145aa2",
+    "X-Forwarded-Host": "127.0.0.1"
+  },
+  "origin": "127.0.0.1, 117.136.46.203",
+  "url": "https://127.0.0.1/get"
+}
+
+```
+
 ## Disable Plugin
 
 To disable the `response-rewrite` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.
diff --git a/docs/zh/latest/plugins/response-rewrite.md b/docs/zh/latest/plugins/response-rewrite.md
index a3701c8af..8cf1b379a 100644
--- a/docs/zh/latest/plugins/response-rewrite.md
+++ b/docs/zh/latest/plugins/response-rewrite.md
@@ -129,6 +129,71 @@ X-Server-balancer_addr: 127.0.0.1:80
 
 :::
 
+使用 `filters` 正则匹配将返回 body 的 X-Amzn-Trace-Id 替换为 X-Amzn-Trace-Id-Replace。
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+  "plugins":{
+    "response-rewrite":{
+      "headers":{
+        "X-Server-id":3,
+        "X-Server-status":"on",
+        "X-Server-balancer_addr":"$balancer_ip:$balancer_port"
+      },
+      "filters":[
+        {
+          "regex":"X-Amzn-Trace-Id",
+          "scope":"global",
+          "replace":"X-Amzn-Trace-Id-Replace"
+        }
+      ],
+      "vars":[
+        [
+          "status",
+          "==",
+          200
+        ]
+      ]
+    }
+  },
+  "upstream":{
+    "type":"roundrobin",
+    "scheme":"https",
+    "nodes":{
+      "httpbin.org:443":1
+    }
+  },
+  "uri":"/*"
+}'
+```
+
+```shell
+curl -X GET -i  http://127.0.0.1:9080/get
+```
+
+```shell
+HTTP/1.1 200 OK
+Transfer-Encoding: chunked
+X-Server-status: on
+X-Server-balancer-addr: 34.206.80.189:443
+X-Server-id: 3
+
+{
+  "args": {},
+  "headers": {
+    "Accept": "*/*",
+    "Host": "127.0.0.1",
+    "User-Agent": "curl/7.29.0",
+    "X-Amzn-Trace-Id-Replace": "Root=1-629e0b89-1e274fdd7c23ca6e64145aa2",
+    "X-Forwarded-Host": "127.0.0.1"
+  },
+  "origin": "127.0.0.1, 117.136.46.203",
+  "url": "https://127.0.0.1/get"
+}
+
+```
+
 ## 禁用插件
 
 当你需要禁用 `response-rewrite` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: