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 eb62ac054 fix: duplicate X-Forwarded-Proto will be sent as string
(#7229)
eb62ac054 is described below
commit eb62ac05468cffdadf63664b499bb699a290827d
Author: soulbird <[email protected]>
AuthorDate: Mon Jun 13 16:52:51 2022 +0800
fix: duplicate X-Forwarded-Proto will be sent as string (#7229)
Co-authored-by: soulbird <[email protected]>
---
apisix/init.lua | 7 ++++++-
t/plugin/proxy-rewrite2.t | 24 ++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/apisix/init.lua b/apisix/init.lua
index 6dc072bdc..f26dee4e1 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -56,6 +56,7 @@ local str_byte = string.byte
local str_sub = string.sub
local tonumber = tonumber
local pairs = pairs
+local type = type
local control_api_router
local is_http = false
@@ -229,7 +230,11 @@ local function set_upstream_headers(api_ctx, picked_server)
local hdr = core.request.header(api_ctx, "X-Forwarded-Proto")
if hdr then
- api_ctx.var.var_x_forwarded_proto = hdr
+ if type(hdr) == "table" then
+ api_ctx.var.var_x_forwarded_proto = hdr[1]
+ else
+ api_ctx.var.var_x_forwarded_proto = hdr
+ end
end
end
diff --git a/t/plugin/proxy-rewrite2.t b/t/plugin/proxy-rewrite2.t
index 4fbfe55ba..fcd4011ba 100644
--- a/t/plugin/proxy-rewrite2.t
+++ b/t/plugin/proxy-rewrite2.t
@@ -208,3 +208,27 @@ X-Forwarded-Proto: grpc
X-Forwarded-Proto: https-rewrite
--- error_log
localhost
+
+
+
+=== TEST 7: pass duplicate X-Forwarded-Proto
+--- apisix_yaml
+routes:
+ -
+ id: 1
+ uri: /echo
+ upstream_id: 1
+upstreams:
+ -
+ id: 1
+ nodes:
+ "127.0.0.1:1980": 1
+ type: roundrobin
+#END
+--- request
+GET /echo
+--- more_headers
+X-Forwarded-Proto: http
+X-Forwarded-Proto: grpc
+--- response_headers
+X-Forwarded-Proto: http