Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicate X-Forwarded-Proto will be sent as string #7229

Merged
merged 5 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
24 changes: 24 additions & 0 deletions t/plugin/proxy-rewrite2.t
Original file line number Diff line number Diff line change
Expand Up @@ -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