mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-05 13:37:34 +08:00
docs: add Attention message for 'response-rewrite' doc. (#2732)
* 1. add Summary for 'zh-cn/plugins/response-rewrite.md' 2. add Attention message for 'response-rewrite' doc. * fix typo * response rewrite plugin, rewrite the content from upstream. -> response rewrite plugin, rewrite the content returned by the upstream as well as Apache APISIX itself.
This commit is contained in:
parent
a6678c33c5
commit
ec5ba5f68c
@ -26,10 +26,11 @@
|
||||
- [**How To Enable**](#how-to-enable)
|
||||
- [**Test Plugin**](#test-plugin)
|
||||
- [**Disable Plugin**](#disable-plugin)
|
||||
- [**Attention**](#Attention)
|
||||
|
||||
## Name
|
||||
|
||||
response rewrite plugin, rewrite the content from upstream.
|
||||
response rewrite plugin, rewrite the content returned by the upstream as well as Apache APISIX itself.
|
||||
|
||||
**senario**:
|
||||
|
||||
@ -116,3 +117,11 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f1
|
||||
```
|
||||
|
||||
The `response rewrite` plugin has been disabled now. It works for other plugins.
|
||||
|
||||
## Attention
|
||||
|
||||
`ngx.exit` will interrupt the execution of the current request and return status code to Nginx.
|
||||
|
||||
![](https://cdn.jsdelivr.net/gh/Miss-you/img/picgo/20201113010623.png)
|
||||
|
||||
However, if you execute `ngx.exit` during the access phase, it only interrupts the request processing phase, and the response phase will still process it, i.e. if you configure the `response-rewrite` plugin, it will force overwriting of your response information (e.g. response status code).
|
||||
|
@ -19,12 +19,21 @@
|
||||
|
||||
- [English](../../plugins/response-rewrite.md)
|
||||
|
||||
# response-rewrite
|
||||
# 目录
|
||||
|
||||
该插件支持修改上游服务返回的 body 和 header 信息。
|
||||
- [**response-rewrite**](#response-rewrite)
|
||||
- [**配置参数**](#配置参数)
|
||||
- [**开启插件**](#开启插件)
|
||||
- [**测试插件**](#测试插件)
|
||||
- [**禁用插件**](#禁用插件)
|
||||
- [**注意事项**](#注意事项)
|
||||
|
||||
## response-rewrite
|
||||
|
||||
该插件支持修改上游服务或网关本身返回的 body 和 header 信息。
|
||||
|
||||
使用场景:
|
||||
1、可以设置 `Access-Control-Allow-*` 等 header 信息,来实现 CORS (跨域资源共享)的功能。
|
||||
1、可以设置 `Access-Control-Allow-*` 等 header 信息,来实现 CORS (跨域资源共享)的功能。
|
||||
2、另外也可以通过配置 status_code 和 header 里面的 Location 来实现重定向,当然如果只是需要重定向功能,最好使用 [redirect](redirect.md) 插件。
|
||||
|
||||
## 配置参数
|
||||
@ -40,7 +49,7 @@
|
||||
|
||||
### 开启插件
|
||||
|
||||
下面是一个示例,在指定的 route 上开启了 `response rewrite` 插件:
|
||||
下面是一个示例,在指定的 route 上开启了 `response rewrite` 插件:
|
||||
|
||||
```shell
|
||||
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
|
||||
@ -85,3 +94,29 @@ X-Server-status: on
|
||||
|
||||
{"code":"ok","message":"new json body"}
|
||||
```
|
||||
|
||||
### 禁用插件
|
||||
|
||||
禁用`response-rewrite`插件很简单。你不需要重新启动服务,只需要在插件配置中删除相应的 json 配置,它将立即生效。
|
||||
|
||||
```shell
|
||||
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
|
||||
{
|
||||
"methods": ["GET"],
|
||||
"uri": "/test/index.html",
|
||||
"upstream": {
|
||||
"type": "roundrobin",
|
||||
"nodes": {
|
||||
"127.0.0.1:80": 1
|
||||
}
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
`ngx.exit`将中断当前请求的执行,并返回状态码给 Nginx。
|
||||
|
||||
![](https://cdn.jsdelivr.net/gh/Miss-you/img/picgo/20201113010623.png)
|
||||
|
||||
但是很多人可能会对`ngx.exit`理解出现偏差,即如果你在`access`阶段执行`ngx.exit`,只是中断了请求处理阶段,响应阶段仍然会处理。比如,如果你配置了`response-rewrite`插件,它会强制覆盖你的响应信息(如响应代码)。
|
||||
|
Loading…
Reference in New Issue
Block a user