Skip to content

Commit

Permalink
feature: support remove header in rewrite plugin. (#692)
Browse files Browse the repository at this point in the history
* feature: support remove header in rewrite plugin.

fixed #658
  • Loading branch information
moonming authored and membphis committed Oct 15, 2019
1 parent 8cee1af commit be49cfc
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 14 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ We provide an online dashboard [demo version](http://apisix.iresty.com), make

APISIX Installed and tested in the following systems, and the version of OpenResty MUST >= 1.15.8.1:

* CentOS 7
* Ubuntu 16.04
* Ubuntu 18.04
* Debian 9
* Debian 10
* macOS
- CentOS 7
- Ubuntu 16.04
- Ubuntu 18.04
- Debian 9
- Debian 10
- macOS
- **ARM64** Ubuntu 18.04

You now have four ways to install APISIX:
- if you are using CentOS 7, it is recommended to use [RPM](#install-from-rpm-for-centos-7);
Expand Down
1 change: 1 addition & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ APISIX 在以下操作系统中可顺利安装并做过运行测试,需要注
- Debian 9
- Debian 10
- macOS
- **ARM64** Ubuntu 18.04

目前有 4 种安装方式:
- 如果你在使用 CentOS 7,我们推荐使用 [RPM 包安装](#通过-rpm-包安装centos-7)
Expand Down
13 changes: 7 additions & 6 deletions doc/plugins/proxy-rewrite-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#### 配置参数
|名字 |可选|说明|
|------- |-----|------|
|scheme |可选| 转发到上游的新`schema` 协议,可以是`http``https`,默认`http`协议|
|uri |可选| 转发到上游的新`uri` 地址|
|host |可选| 转发到上游的新`host` 地址,例如:`iresty.com` |
|enable_websocket|可选| 是否启用`websocket`(布尔值),默认不启用|
|headers |可选| 转发到上游的新`headers`,可以设置多个。头信息如果存在将重写,不存在则添加。|
|scheme |可选| 转发到上游的新 `schema` 协议,可以是 `http``https`,默认 `http` 协议|
|uri |可选| 转发到上游的新 `uri` 地址|
|host |可选| 转发到上游的新 `host` 地址,例如:`iresty.com` |
|enable_websocket|可选| 是否启用 `websocket`(布尔值),默认不启用|
|headers |可选| 转发到上游的新`headers`,可以设置多个。头信息如果存在将重写,不存在则添加。想要删除某个 header 的话,把对应的值设置为空字符串即可|

### 示例

Expand All @@ -30,7 +30,8 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
"enable_websocket": true,
"headers": {
"X-Api-Version": "v1",
"X-Api-Engine": "apisix"
"X-Api-Engine": "apisix",
"X-Api-useless": "",
}
}
},
Expand Down
5 changes: 3 additions & 2 deletions doc/plugins/proxy-rewrite.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ upstream proxy info rewrite plugin.
|uri |No| Upstream new `uri` forwarding address.|
|host |No| Upstream new `host` forwarding address, example `iresty.com`. |
|enable_websocket|No| enable `websocket`(boolean), default `false`.|
|headers |No| Forward to the new `headers` of the upstream, can set up multiple. If it exists, rewrite the header; if it does not exist, add the header.|
|headers |No| Forward to the new `headers` of the upstream, can set up multiple. If it exists, will rewrite the header, otherwise will add the header. You can set the corresponding value to an empty string to remove a header.|

### Example

Expand All @@ -30,7 +30,8 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
"enable_websocket": true,
"headers": {
"X-Api-Version": "v1",
"X-Api-Engine": "apisix"
"X-Api-Engine": "apisix",
"X-Api-useless": ""
}
}
},
Expand Down
58 changes: 58 additions & 0 deletions t/plugin/proxy-rewrite.t
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,61 @@ GET /hello HTTP/1.1
uri: /plugin_proxy_rewrite_args
--- no_error_log
[error]



=== TEST 24: remove header
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"proxy-rewrite": {
"uri": "/uri/plugin_proxy_rewrite",
"headers": {
"X-Api-Engine": "APISIX",
"X-Api-Test": ""
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]



=== TEST 25: remove header
--- request
GET /hello HTTP/1.1
--- more_headers
X-Api-Test: foo
X-Api-Engine: bar
--- response_body
uri: /uri/plugin_proxy_rewrite
host: localhost
x-api-engine: APISIX
x-real-ip: 127.0.0.1
--- no_error_log
[error]

0 comments on commit be49cfc

Please sign in to comment.