From e31281e3f43ad5ba555812cc6c1148b1e5f4f253 Mon Sep 17 00:00:00 2001 From: zhu327 Date: Tue, 8 Aug 2023 11:15:23 +0800 Subject: [PATCH 1/3] bugfix: header rewrite empty --- src/apisix/plugins/bk-stage-header-rewrite.lua | 3 --- src/apisix/t/bk-stage-header-rewrite.t | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/apisix/plugins/bk-stage-header-rewrite.lua b/src/apisix/plugins/bk-stage-header-rewrite.lua index 8745b6e..37870f8 100644 --- a/src/apisix/plugins/bk-stage-header-rewrite.lua +++ b/src/apisix/plugins/bk-stage-header-rewrite.lua @@ -39,7 +39,6 @@ local schema = { properties = { add = { type = "object", - minProperties = 1, patternProperties = { ["^[^:]+$"] = { oneOf = { @@ -51,7 +50,6 @@ local schema = { }, set = { type = "object", - minProperties = 1, patternProperties = { ["^[^:]+$"] = { oneOf = { @@ -63,7 +61,6 @@ local schema = { }, remove = { type = "array", - minItems = 1, items = { type = "string", -- "Referer" diff --git a/src/apisix/t/bk-stage-header-rewrite.t b/src/apisix/t/bk-stage-header-rewrite.t index fc9ee4e..3ff8ece 100644 --- a/src/apisix/t/bk-stage-header-rewrite.t +++ b/src/apisix/t/bk-stage-header-rewrite.t @@ -105,7 +105,8 @@ passed "bk-stage-header-rewrite": { "set": { "X-Api-Version": "v2" - } + }, + "remove": [] } }, "upstream": { From e4620f5c5d659a55de1aec93a55f0982d13934ac Mon Sep 17 00:00:00 2001 From: zhu327 Date: Tue, 8 Aug 2023 12:22:17 +0800 Subject: [PATCH 2/3] bugfix: header rewrite empty --- src/apisix/t/bk-stage-header-rewrite.t | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/apisix/t/bk-stage-header-rewrite.t b/src/apisix/t/bk-stage-header-rewrite.t index 3ff8ece..3169da5 100644 --- a/src/apisix/t/bk-stage-header-rewrite.t +++ b/src/apisix/t/bk-stage-header-rewrite.t @@ -355,3 +355,42 @@ uri: /uri/plugin_proxy_rewrite host: localhost x-api-engine: APISIX x-real-ip: 127.0.0.1 + +=== TEST 13: remove header set empty +--- 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": { + "bk-proxy-rewrite": { + "uri": "/uri/plugin_proxy_rewrite" + }, + "bk-stage-header-rewrite": { + "add": {}, + "set": {}, + "remove": ["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 From b0472ebbecee158974870e97a18b58ed95c6816c Mon Sep 17 00:00:00 2001 From: zhu327 Date: Tue, 8 Aug 2023 17:16:27 +0800 Subject: [PATCH 3/3] bugfix: header rewrite empty --- src/apisix/t/bk-stage-header-rewrite.t | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/apisix/t/bk-stage-header-rewrite.t b/src/apisix/t/bk-stage-header-rewrite.t index 3169da5..9a03c60 100644 --- a/src/apisix/t/bk-stage-header-rewrite.t +++ b/src/apisix/t/bk-stage-header-rewrite.t @@ -394,3 +394,15 @@ x-real-ip: 127.0.0.1 GET /t --- response_body passed + +=== TEST 14: remove header set empty ok +--- 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: bar +x-real-ip: 127.0.0.1