You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/06/06 07:44:19 UTC

[GitHub] [apisix] zhendongcmss opened a new pull request, #7197: docs: add re case on response-rewrite plugin

zhendongcmss opened a new pull request, #7197:
URL: https://github.com/apache/apisix/pull/7197

   ### Description
   
   <!-- Please include a summary of the change and which issue is fixed. -->
   <!-- Please also include relevant motivation and context. -->
   
   Fixes # (issue) https://github.com/apache/apisix/issues/7130
   
   ### Checklist
   
   - [ ] I have explained the need for this PR and the problem it solves
   - [ ] I have explained the changes or the new features added to this PR
   - [ ] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [ ] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
   
   <!--
   
   Note
   
   1. Mark the PR as draft until it's ready to be reviewed.
   2. Always add/update tests for any changes unless you have a good reason.
   3. Always update the documentation to reflect the changes made in the PR.
   4. Make a new commit to resolve conversations instead of `push -f`.
   5. To resolve merge conflicts, merge master instead of rebasing.
   6. Use "request review" to notify the reviewer after making changes.
   7. Only a reviewer can mark a conversation as resolved.
   
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] navendu-pottekkat commented on a diff in pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
navendu-pottekkat commented on code in PR #7197:
URL: https://github.com/apache/apisix/pull/7197#discussion_r891854927


##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -118,6 +118,71 @@ X-Server-balancer_addr: 127.0.0.1:80
 {"code":"ok","message":"new json body"}
 ```
 
+Replace the string X-Amzn-Trace-Id of body to X-Amzn-Trace-Id-Replace with `filters` regular expression.

Review Comment:
   @zhendongcmss Could you change to the above sentence here as well?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] soulbird commented on a diff in pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #7197:
URL: https://github.com/apache/apisix/pull/7197#discussion_r890681587


##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -118,6 +118,45 @@ X-Server-balancer_addr: 127.0.0.1:80
 {"code":"ok","message":"new json body"}
 ```
 
+Replace the string client_addr of body to client_addr_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": "client_addr", "scope": "global", "replace": "client_addr_replace"}],
+            "vars":[
+                [ "status","==",200 ]
+            ]
+    }
+  },
+  "upstream": {
+    "type": "roundrobin",
+    "nodes": {
+      "127.0.0.1:8881": 1

Review Comment:
   LGTM



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] navendu-pottekkat commented on a diff in pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
navendu-pottekkat commented on code in PR #7197:
URL: https://github.com/apache/apisix/pull/7197#discussion_r890780691


##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -118,6 +118,71 @@ X-Server-balancer_addr: 127.0.0.1:80
 {"code":"ok","message":"new json body"}
 ```
 
+Replace the string X-Amzn-Trace-Id of body to X-Amzn-Trace-Id-Replace.

Review Comment:
   This could be added as an example. But it is not clear to me that we are replacing the header using regex.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] zhendongcmss commented on a diff in pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on code in PR #7197:
URL: https://github.com/apache/apisix/pull/7197#discussion_r890714860


##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -118,6 +118,61 @@ X-Server-balancer_addr: 127.0.0.1:80
 {"code":"ok","message":"new json body"}
 ```
 
+Replace the string X-Amzn-Trace-Id of body to 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": {

Review Comment:
   sure



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] Qizhd commented on a diff in pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
Qizhd commented on code in PR #7197:
URL: https://github.com/apache/apisix/pull/7197#discussion_r890201820


##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -118,6 +118,45 @@ X-Server-balancer_addr: 127.0.0.1:80
 {"code":"ok","message":"new json body"}
 ```
 
+Replace the string client_addr of body to client_addr_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": "client_addr", "scope": "global", "replace": "client_addr_replace"}],
+            "vars":[
+                [ "status","==",200 ]
+            ]
+    }
+  },
+  "upstream": {
+    "type": "roundrobin",
+    "nodes": {
+      "127.0.0.1:8881": 1

Review Comment:
   updated



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] soulbird commented on a diff in pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #7197:
URL: https://github.com/apache/apisix/pull/7197#discussion_r889951421


##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -118,6 +118,45 @@ X-Server-balancer_addr: 127.0.0.1:80
 {"code":"ok","message":"new json body"}
 ```
 
+Replace the string client_addr of body to client_addr_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": "client_addr", "scope": "global", "replace": "client_addr_replace"}],
+            "vars":[
+                [ "status","==",200 ]
+            ]
+    }
+  },
+  "upstream": {
+    "type": "roundrobin",
+    "nodes": {
+      "127.0.0.1:8881": 1

Review Comment:
   `httpbin.org` is recommended, no one knows what `127.0.0.1:8881` will respond to.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] navendu-pottekkat commented on a diff in pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
navendu-pottekkat commented on code in PR #7197:
URL: https://github.com/apache/apisix/pull/7197#discussion_r891009524


##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -118,6 +118,71 @@ X-Server-balancer_addr: 127.0.0.1:80
 {"code":"ok","message":"new json body"}
 ```
 
+Replace the string X-Amzn-Trace-Id of body to X-Amzn-Trace-Id-Replace with `filters` regular expression.

Review Comment:
   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:



##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -118,6 +118,71 @@ X-Server-balancer_addr: 127.0.0.1:80
 {"code":"ok","message":"new json body"}
 ```
 
+Replace the string X-Amzn-Trace-Id of body to X-Amzn-Trace-Id-Replace with `filters` regular expression.
+
+```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"
+}
+
+```
+

Review Comment:
   It might be better if we move the `:::info IMPORTANT` section before this example.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] juzhiyuan commented on a diff in pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on code in PR #7197:
URL: https://github.com/apache/apisix/pull/7197#discussion_r890686985


##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -118,6 +118,61 @@ X-Server-balancer_addr: 127.0.0.1:80
 {"code":"ok","message":"new json body"}
 ```
 
+Replace the string X-Amzn-Trace-Id of body to 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": {

Review Comment:
   Could you please format the JSON with 2 spaces only? You can use tools like https://www.json.cn/



##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -47,7 +47,7 @@ You can also use the [redirect](./redirect.md) Plugin to setup redirects.
 | Name        | Type    | Required | Default | Valid values                                                                                                  | Description                                                                                                                                                                                                                                                                                                     |
 |-------------|---------|----------|---------|---------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
 | status_code | integer | False    |         | [200, 598]                                                                                                    | New HTTP status code in the response. If unset, falls back to the original status code.                                                                                                                                                                                                                         |
-| body        | string  | False    |         |                                                                                                               | New body of the response. The content-length would also be reset.                                                                                                                                                                                                                                               |
+| body        | string  | False    |         |                                                                                                               | New body of the response. The content-length would also be reset. If body and filters configured at the same time, body configuration will not work.                                                                                                                                                                                                                                            |

Review Comment:
   Hi,
   
   The below of the parameter table, here has one tip: 
   
   ![image](https://user-images.githubusercontent.com/2106987/172272971-2850d52a-8b6b-4d19-b389-dccd19150938.png)
   
   Because you updated this part, I think you missed the tip when you used cc @navendu-pottekkat. Do you have ideas to make the Tip more highlighted?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] zhendongcmss commented on a diff in pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on code in PR #7197:
URL: https://github.com/apache/apisix/pull/7197#discussion_r891826920


##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -118,6 +118,71 @@ X-Server-balancer_addr: 127.0.0.1:80
 {"code":"ok","message":"new json body"}
 ```
 
+Replace the string X-Amzn-Trace-Id of body to X-Amzn-Trace-Id-Replace with `filters` regular expression.
+
+```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"
+}
+
+```
+

Review Comment:
   updated



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] juzhiyuan commented on a diff in pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on code in PR #7197:
URL: https://github.com/apache/apisix/pull/7197#discussion_r890738199


##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -118,6 +118,71 @@ X-Server-balancer_addr: 127.0.0.1:80
 {"code":"ok","message":"new json body"}
 ```
 
+Replace the string X-Amzn-Trace-Id of body to X-Amzn-Trace-Id-Replace.

Review Comment:
   Hi, the changes you added are more like a scenario section (not related to the `Enabling` section), please see https://github.com/apache/apisix/blob/a729489152a032571b9bcd9b19edc75949755fbe/docs/en/latest/plugins/response-rewrite.md
   
   ![image](https://user-images.githubusercontent.com/2106987/172291030-8f35e5a2-c0d3-4e67-bd9a-d7c99299db48.png)
   
   cc @navendu-pottekkat should we accept this? If yes, then what titles should we use?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] zhendongcmss commented on a diff in pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on code in PR #7197:
URL: https://github.com/apache/apisix/pull/7197#discussion_r892045283


##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -118,6 +118,71 @@ X-Server-balancer_addr: 127.0.0.1:80
 {"code":"ok","message":"new json body"}
 ```
 
+Replace the string X-Amzn-Trace-Id of body to X-Amzn-Trace-Id-Replace with `filters` regular expression.

Review Comment:
   sure



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] zhendongcmss commented on a diff in pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on code in PR #7197:
URL: https://github.com/apache/apisix/pull/7197#discussion_r890714750


##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -47,7 +47,7 @@ You can also use the [redirect](./redirect.md) Plugin to setup redirects.
 | Name        | Type    | Required | Default | Valid values                                                                                                  | Description                                                                                                                                                                                                                                                                                                     |
 |-------------|---------|----------|---------|---------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
 | status_code | integer | False    |         | [200, 598]                                                                                                    | New HTTP status code in the response. If unset, falls back to the original status code.                                                                                                                                                                                                                         |
-| body        | string  | False    |         |                                                                                                               | New body of the response. The content-length would also be reset.                                                                                                                                                                                                                                               |
+| body        | string  | False    |         |                                                                                                               | New body of the response. The content-length would also be reset. If body and filters configured at the same time, body configuration will not work.                                                                                                                                                                                                                                            |

Review Comment:
   I miss the tips.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] spacewander merged pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
spacewander merged PR #7197:
URL: https://github.com/apache/apisix/pull/7197


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] zhendongcmss commented on a diff in pull request #7197: docs: add re case on response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on code in PR #7197:
URL: https://github.com/apache/apisix/pull/7197#discussion_r890841102


##########
docs/en/latest/plugins/response-rewrite.md:
##########
@@ -118,6 +118,71 @@ X-Server-balancer_addr: 127.0.0.1:80
 {"code":"ok","message":"new json body"}
 ```
 
+Replace the string X-Amzn-Trace-Id of body to X-Amzn-Trace-Id-Replace.

Review Comment:
   I add description let it clear.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org