同步操作将从 iresty/Apache APISIX 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
response rewrite plugin, rewrite the content from upstream.
senario:
Access-Control-Allow-*
series field to support CORS(Cross-origin Resource Sharing).status_code
and Location
field in header to achieve redirect, you can alse use redirect plugin if you just want a redirect function.functionName | Requirement | Description |
---|---|---|
status_code | optional | New status code to client |
body | optional | New body to client, and the content-length will be reset too. |
headers | optional | Set the new headers for client, can set up multiple. If it exists already from upstream, will rewrite the header, otherwise will add the header. You can set the corresponding value to an empty string to remove a header. |
Here's an example, enable the response rewrite
plugin on the specified route:
curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
"methods": ["GET"],
"uri": "/test/index.html",
"plugins": {
"response-rewrite": {
"body": "{\"code\":\"ok\",\"message\":\"new json body\"}",
"headers": {
"X-Server-id": 3,
"X-Server-status": "on"
}
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:80": 1
}
}
}'
Testing based on the above examples :
curl -X GET -i http://127.0.0.1:9080/test/index.html
It will output like below,no matter what kind of content from upstream.
HTTP/1.1 200 OK
Date: Sat, 16 Nov 2019 09:15:12 GMT
Transfer-Encoding: chunked
Connection: keep-alive
X-Server-id: 3
X-Server-status: on
{"code":"ok","message":"new json body"}
This means that the response rewrite
plugin is in effect.
When you want to disable the response rewrite
plugin, it is very simple,
you can delete the corresponding json configuration in the plugin configuration,
no need to restart the service, it will take effect immediately:
curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
"methods": ["GET"],
"uri": "/test/index.html",
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:80": 1
}
}
}'
The response rewrite
plugin has been disabled now. It works for other plugins.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。