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 2021/10/29 10:32:55 UTC
[GitHub] [apisix] tzssangglass commented on issue #5370: bug: response-rewrite does not take effect in apisix-openresty
tzssangglass commented on issue #5370:
URL: https://github.com/apache/apisix/issues/5370#issuecomment-954635418
here is my config:
```
{
"plugins": {
"response-rewrite": {
"headers": {
"X-Server-id": 3,
"X-Server-status": "on",
"X-Server-balancer_addr": "$balancer_ip:$balancer_port"
}
}
},
"upstream": {
"nodes": {
"httpbin.org:80": 1
},
"type": "roundrobin"
},
"uri": "/*"
}
```
I remove `vars` as your config, and this is my result:
```
curl -i 127.0.0.1:9080/get
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 300
Connection: keep-alive
Date: Fri, 29 Oct 2021 10:20:56 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Server: APISIX/2.10.1
X-Server-balancer-addr: 198.18.1.159:80
X-Server-id: 3
X-Server-status: on
{
"args": {},
"headers": {
"Accept": "*/*",
"Host": "127.0.0.1",
"User-Agent": "curl/7.64.1",
"X-Amzn-Trace-Id": "Root=1-617bcb08-2d3f0fd4294f31de7cd37f99",
"X-Forwarded-Host": "127.0.0.1"
},
"origin": "127.0.0.1, 180.118.190.54",
"url": "http://127.0.0.1/get"
}
```
you can see the `response-rewrite` plugin workes well. I think `response-rewrite` is not working because `vars` is incorrect.
the correct configuration should be
```
{
"plugins": {
"response-rewrite": {
"headers": {
"X-Server-id": 3,
"X-Server-status": "on",
"X-Server-balancer_addr": "$balancer_ip:$balancer_port"
},
"vars": [
[
"status",
"==",
200
]
]
}
},
"upstream": {
"nodes": {
"httpbin.org:80": 1
},
"type": "roundrobin"
},
"uri": "/*"
}
```
`200` is number type, not string type.
There is an error in the example in this document: https://github.com/apache/apisix/blob/master/docs/en/latest/plugins/response-rewrite.md#how-to-enable, would you like to submit a PR to fix it?
just change `[ "status","==","200" ]` to `[ "status","==",200 ]`.
--
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