This is an automated email from the ASF dual-hosted git repository.
young 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 df3cc407a fix(plugin/redirect): ensure redirect when scheme is not
`https` (#12561)
df3cc407a is described below
commit df3cc407a0df96c801638300c8eb4eb6a53c000d
Author: YYYoung <[email protected]>
AuthorDate: Fri Sep 19 08:39:02 2025 +0800
fix(plugin/redirect): ensure redirect when scheme is not `https` (#12561)
* fix(plugin/redirect): ensure redirect when scheme is not `https`
* test: add redirect when not https case
---
apisix/plugins/redirect.lua | 2 +-
t/plugin/redirect.t | 14 +++++++++++++-
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/apisix/plugins/redirect.lua b/apisix/plugins/redirect.lua
index 421007d20..c553ccd7e 100644
--- a/apisix/plugins/redirect.lua
+++ b/apisix/plugins/redirect.lua
@@ -191,7 +191,7 @@ function _M.rewrite(conf, ctx)
local proxy_proto = core.request.header(ctx, "X-Forwarded-Proto")
local _scheme = proxy_proto or core.request.get_scheme(ctx)
- if conf.http_to_https and _scheme == "http" then
+ if conf.http_to_https and _scheme ~= "https" then
if ret_port == nil or ret_port == 443 or ret_port <= 0 or ret_port >
65535 then
uri = "https://$host$request_uri"
else
diff --git a/t/plugin/redirect.t b/t/plugin/redirect.t
index e27f2f7b6..87847bfa4 100644
--- a/t/plugin/redirect.t
+++ b/t/plugin/redirect.t
@@ -1046,7 +1046,19 @@ Location: https://foo.com:9443/hello
-=== TEST 47: wrong configure, enable http_to_https with append_query_string
+=== TEST 47: pass wrong X-Forwarded-Proto, should not affect the redirect
+--- request
+GET /hello
+--- more_headers
+Host: foo.com
+X-Forwarded-Proto: any
+--- error_code: 301
+--- response_headers
+Location: https://foo.com:9443/hello
+
+
+
+=== TEST 48: wrong configure, enable http_to_https with append_query_string
--- config
location /t {
content_by_lua_block {