Skip to content

Commit

Permalink
docs: add re case on response-rewrite plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
zhendongcmss committed Jun 7, 2022
1 parent 22e23ba commit bd52bd5
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
65 changes: 65 additions & 0 deletions docs/en/latest/plugins/response-rewrite.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

```

:::info IMPORTANT

[ngx.exit](https://openresty-reference.readthedocs.io/en/latest/Lua_Nginx_API/#ngxexit) will interrupt the execution of a request and returns its status code to Nginx.
Expand Down
65 changes: 65 additions & 0 deletions docs/zh/latest/plugins/response-rewrite.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,71 @@ X-Server-balancer_addr: 127.0.0.1:80
{"code":"ok","message":"new json body"}
```

使用正则匹配将返回 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"
}

```

:::info IMPORTANT

[ngx.exit](https://openresty-reference.readthedocs.io/en/latest/Lua_Nginx_API/#ngxexit) 将会中断当前请求的执行并将其状态码返回给 NGINX。
Expand Down

0 comments on commit bd52bd5

Please sign in to comment.