Copilot commented on code in PR #13292:
URL: https://github.com/apache/apisix/pull/13292#discussion_r3136471840


##########
docs/en/latest/plugins/proxy-rewrite.md:
##########
@@ -505,3 +505,87 @@ curl -i "http://127.0.0.1:9080/get";
 ```
 
 You should receive an `HTTP/1.1 403 Forbidden` response.
+
+### Dynamically Forward Requests in `radixtree_uri_with_parameter` Router Mode
+
+The following example demonstrates how to extract part of the URL path using 
the `uri_param_*` variable and forward the value to the Upstream service in a 
new header. This example assumes that APISIX is operating in the 
`radixtree_uri_with_parameter` [router mode](../router-radixtree.md).
+
+Create a Route as such:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "httpbin",
+    "uri": "/anything/user/:user_id/profile",
+    "plugins": {
+      "proxy-rewrite": {
+        "headers": {
+          "set": {
+            "X-User-ID": "$uri_param_user_id"
+          }
+        }
+      }
+    },
+    "upstream": {
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
+    }
+  }'
+```
+
+`/anything/user/:user_id/profile` matches requests where `user_id` is a route 
parameter. The Plugin is configured to assign the `user_id` parameter value to 
a new header `X-User-ID`.
+
+Send a request to the Route:
+
+```shell
+curl "http://127.0.0.1:9080/anything/user/123/profile";
+```
+
+You should see a response similar to the following:
+
+```json
+{
+  "args": {},
+  "data": "",
+  "files": {},
+  "form": {},
+  "headers": {
+    "Accept": "*/*",
+    "Host": "127.0.0.1",
+    "User-Agent": "curl/8.6.0",
+    "X-Amzn-Trace-Id": "Root=1-68873cf5-7248f64d19d607ea50aa9735",
+    "X-Forwarded-Host": "127.0.0.1",
+    "X-User-Id": "123"
+  },
+  ...

Review Comment:
   The response example is fenced as `json` but includes an ellipsis (`...`), 
which makes it invalid JSON for copy/paste. Consider changing the fence to 
`text` or removing the ellipsis and showing a complete JSON object.



##########
docs/en/latest/plugins/proxy-rewrite.md:
##########
@@ -505,3 +505,87 @@ curl -i "http://127.0.0.1:9080/get";
 ```
 
 You should receive an `HTTP/1.1 403 Forbidden` response.
+
+### Dynamically Forward Requests in `radixtree_uri_with_parameter` Router Mode
+
+The following example demonstrates how to extract part of the URL path using 
the `uri_param_*` variable and forward the value to the Upstream service in a 
new header. This example assumes that APISIX is operating in the 
`radixtree_uri_with_parameter` [router mode](../router-radixtree.md).
+
+Create a Route as such:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "httpbin",
+    "uri": "/anything/user/:user_id/profile",
+    "plugins": {
+      "proxy-rewrite": {
+        "headers": {
+          "set": {
+            "X-User-ID": "$uri_param_user_id"
+          }

Review Comment:
   The configured header name is `X-User-ID`, but the shown upstream response 
uses `X-User-Id` (different casing). To avoid confusion, align the casing in 
the example output or add a short note that upstream services may normalize 
header casing.



##########
docs/zh/latest/plugins/proxy-rewrite.md:
##########
@@ -505,3 +505,87 @@ curl -i "http://127.0.0.1:9080/get";
 ```
 
 您应该收到 `HTTP/1.1 403 Forbidden` 响应。
+
+### 在 `radixtree_uri_with_parameter` 路由模式下动态转发请求
+
+以下示例演示如何使用 `uri_param_*` 变量提取 URL 路径的一部分,并将其值转发到上游服务的新标头中。此示例假设 APISIX 运行在 
`radixtree_uri_with_parameter` [路由模式](../router-radixtree.md)下。
+
+创建如下路由:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "httpbin",
+    "uri": "/anything/user/:user_id/profile",
+    "plugins": {
+      "proxy-rewrite": {
+        "headers": {
+          "set": {
+            "X-User-ID": "$uri_param_user_id"
+          }
+        }
+      }
+    },
+    "upstream": {
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
+    }
+  }'
+```
+
+`/anything/user/:user_id/profile` 匹配 `user_id` 为路由参数的请求。插件配置为将 `user_id` 
参数值赋给新标头 `X-User-ID`。
+
+发送请求到路由:
+
+```shell
+curl "http://127.0.0.1:9080/anything/user/123/profile";
+```
+
+您应该看到类似于以下内容的响应:
+
+```json
+{
+  "args": {},
+  "data": "",
+  "files": {},
+  "form": {},
+  "headers": {
+    "Accept": "*/*",
+    "Host": "127.0.0.1",
+    "User-Agent": "curl/8.6.0",
+    "X-Amzn-Trace-Id": "Root=1-68873cf5-7248f64d19d607ea50aa9735",
+    "X-Forwarded-Host": "127.0.0.1",
+    "X-User-Id": "123"
+  },
+  ...

Review Comment:
   响应示例使用了 `json` 代码块,但内容里包含省略号(`...`),这会导致示例不是有效 JSON,读者复制粘贴时可能失败。建议将代码块类型改为 
`text`,或去掉省略号并提供完整 JSON。



##########
docs/zh/latest/plugins/proxy-rewrite.md:
##########
@@ -505,3 +505,87 @@ curl -i "http://127.0.0.1:9080/get";
 ```
 
 您应该收到 `HTTP/1.1 403 Forbidden` 响应。
+
+### 在 `radixtree_uri_with_parameter` 路由模式下动态转发请求
+
+以下示例演示如何使用 `uri_param_*` 变量提取 URL 路径的一部分,并将其值转发到上游服务的新标头中。此示例假设 APISIX 运行在 
`radixtree_uri_with_parameter` [路由模式](../router-radixtree.md)下。
+
+创建如下路由:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "httpbin",
+    "uri": "/anything/user/:user_id/profile",
+    "plugins": {
+      "proxy-rewrite": {
+        "headers": {
+          "set": {
+            "X-User-ID": "$uri_param_user_id"
+          }

Review Comment:
   示例中设置的请求标头名为 `X-User-ID`,但响应示例里显示为 
`X-User-Id`(大小写不一致)。建议统一示例中的大小写,或补充说明上游服务可能会规范化标头名称大小写。



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to