From 8ccffdf5002c0a1a6333d9109831ea7cf845e59d Mon Sep 17 00:00:00 2001 From: soulbird Date: Thu, 29 Dec 2022 18:02:08 +0800 Subject: [PATCH 1/2] fix(ext-plugin-post-resp): can't set content-type response header --- apisix/plugins/ext-plugin/init.lua | 1 - t/lib/ext-plugin.lua | 2 ++ t/plugin/ext-plugin/response.t | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apisix/plugins/ext-plugin/init.lua b/apisix/plugins/ext-plugin/init.lua index 0f9e0de14e5f..2e9a7494e44d 100644 --- a/apisix/plugins/ext-plugin/init.lua +++ b/apisix/plugins/ext-plugin/init.lua @@ -76,7 +76,6 @@ local exclude_resp_header = { ["server"] = true, ["www-authenticate"] = true, ["content-encoding"] = true, - ["content-type"] = true, ["content-location"] = true, ["content-language"] = true, } diff --git a/t/lib/ext-plugin.lua b/t/lib/ext-plugin.lua index 6403e74f5c5b..b19a79838591 100644 --- a/t/lib/ext-plugin.lua +++ b/t/lib/ext-plugin.lua @@ -534,6 +534,8 @@ function _M.go(case) if runner and runner == "Go-runner" then headers["x-runner"] = "Test-Runner" end + + headers["Content-Type"] = "application/json" end local i = 1 diff --git a/t/plugin/ext-plugin/response.t b/t/plugin/ext-plugin/response.t index 2500e5db0e96..d8a2be2a56e6 100644 --- a/t/plugin/ext-plugin/response.t +++ b/t/plugin/ext-plugin/response.t @@ -155,6 +155,7 @@ resp-X-Runner: Go-runner --- error_code: 200 --- response_headers X-Runner: Test-Runner +Content-Type: application/json --- response_body hello world From c40a813ccc9a36fd3571238f39e54ada29d2c7f3 Mon Sep 17 00:00:00 2001 From: soulbird Date: Tue, 3 Jan 2023 17:54:31 +0800 Subject: [PATCH 2/2] remove exclude resp headers --- apisix/plugins/ext-plugin/init.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/apisix/plugins/ext-plugin/init.lua b/apisix/plugins/ext-plugin/init.lua index 2e9a7494e44d..b6fcf6fea82c 100644 --- a/apisix/plugins/ext-plugin/init.lua +++ b/apisix/plugins/ext-plugin/init.lua @@ -76,6 +76,7 @@ local exclude_resp_header = { ["server"] = true, ["www-authenticate"] = true, ["content-encoding"] = true, + ["content-type"] = true, ["content-location"] = true, ["content-language"] = true, } @@ -790,13 +791,11 @@ local rpc_handlers = { for i = 1, len do local entry = call_resp:Headers(i) local name = str_lower(entry:Name()) - if not exclude_resp_header[name] then - if resp_headers[name] == nil then - core.response.set_header(name, entry:Value()) - resp_headers[name] = true - else - core.response.add_header(name, entry:Value()) - end + if resp_headers[name] == nil then + core.response.set_header(name, entry:Value()) + resp_headers[name] = true + else + core.response.add_header(name, entry:Value()) end end else