From be49cfcc196502f06b9d9b9096012526a37c5de3 Mon Sep 17 00:00:00 2001 From: WenMing Date: Tue, 15 Oct 2019 16:06:28 +0800 Subject: [PATCH] feature: support remove header in rewrite plugin. (#692) * feature: support remove header in rewrite plugin. fixed https://github.com/iresty/apisix/issues/658 --- README.md | 13 ++++---- README_CN.md | 1 + doc/plugins/proxy-rewrite-cn.md | 13 ++++---- doc/plugins/proxy-rewrite.md | 5 +-- t/plugin/proxy-rewrite.t | 58 +++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 464ee138f08c..4d117c7ea867 100644 --- a/README.md +++ b/README.md @@ -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); diff --git a/README_CN.md b/README_CN.md index 8fbb52e67733..453c943c219c 100644 --- a/README_CN.md +++ b/README_CN.md @@ -76,6 +76,7 @@ APISIX 在以下操作系统中可顺利安装并做过运行测试,需要注 - Debian 9 - Debian 10 - macOS +- **ARM64** Ubuntu 18.04 目前有 4 种安装方式: - 如果你在使用 CentOS 7,我们推荐使用 [RPM 包安装](#通过-rpm-包安装centos-7); diff --git a/doc/plugins/proxy-rewrite-cn.md b/doc/plugins/proxy-rewrite-cn.md index e37e80e0d755..8757ee3376a7 100644 --- a/doc/plugins/proxy-rewrite-cn.md +++ b/doc/plugins/proxy-rewrite-cn.md @@ -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 的话,把对应的值设置为空字符串即可| ### 示例 @@ -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": "", } } }, diff --git a/doc/plugins/proxy-rewrite.md b/doc/plugins/proxy-rewrite.md index 16c8a3a040e5..0a2e4c202879 100644 --- a/doc/plugins/proxy-rewrite.md +++ b/doc/plugins/proxy-rewrite.md @@ -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 @@ -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": "" } } }, diff --git a/t/plugin/proxy-rewrite.t b/t/plugin/proxy-rewrite.t index a374adec3fef..ef34af2c45c5 100644 --- a/t/plugin/proxy-rewrite.t +++ b/t/plugin/proxy-rewrite.t @@ -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]