You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/04/26 02:15:35 UTC

[apisix] branch master updated: fix: the same fix to other headers (#6921)

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 307b03baf fix: the same fix to other headers (#6921)
307b03baf is described below

commit 307b03baf3f4376573ea5c924fd60a39167ee272
Author: 蚊子先生 <52...@users.noreply.github.com>
AuthorDate: Tue Apr 26 10:15:30 2022 +0800

    fix: the same fix to other headers (#6921)
    
    Co-authored-by: jiangyuncong <ji...@cecinvestment.com>
---
 apisix/plugins/ext-plugin/init.lua  |  9 ++++++++-
 t/lib/ext-plugin.lua                |  2 ++
 t/plugin/ext-plugin/http-req-call.t | 22 ++++++++++++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/apisix/plugins/ext-plugin/init.lua b/apisix/plugins/ext-plugin/init.lua
index ad91802b9..063501deb 100644
--- a/apisix/plugins/ext-plugin/init.lua
+++ b/apisix/plugins/ext-plugin/init.lua
@@ -577,9 +577,16 @@ local rpc_handlers = {
 
             local len = stop:HeadersLength()
             if len > 0 then
+                local stop_resp_headers = {}
                 for i = 1, len do
                     local entry = stop:Headers(i)
-                    core.response.set_header(entry:Name(), entry:Value())
+                    local name = str_lower(entry:Name())
+                    if stop_resp_headers[name] == nil then
+                        core.response.set_header(name, entry:Value())
+                        stop_resp_headers[name] = true
+                    else
+                        core.response.add_header(name, entry:Value())
+                    end
                 end
             end
 
diff --git a/t/lib/ext-plugin.lua b/t/lib/ext-plugin.lua
index b83817704..c74464eaa 100644
--- a/t/lib/ext-plugin.lua
+++ b/t/lib/ext-plugin.lua
@@ -251,6 +251,8 @@ function _M.go(case)
             local hdrs = {
                 {"X-Resp", "foo"},
                 {"X-Req", "bar"},
+                {"X-Same", "one"},
+                {"X-Same", "two"},
             }
             local len = #hdrs
             local textEntries = {}
diff --git a/t/plugin/ext-plugin/http-req-call.t b/t/plugin/ext-plugin/http-req-call.t
index 591f31692..7d4f678b7 100644
--- a/t/plugin/ext-plugin/http-req-call.t
+++ b/t/plugin/ext-plugin/http-req-call.t
@@ -728,3 +728,25 @@ plugin_proxy_rewrite_resp_header
 X-Resp: foo
 X-Req: bar
 X-Same: one, two
+
+
+
+=== TEST 26: stop with modify same response headers
+--- request
+GET /hello
+--- response_body chomp
+cat
+--- extra_stream_config
+    server {
+        listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
+
+        content_by_lua_block {
+            local ext = require("lib.ext-plugin")
+            ext.go({stop = true})
+        }
+    }
+--- error_code: 405
+--- response_headers
+X-Resp: foo
+X-Req: bar
+X-Same: one, two