diff --git a/apisix/plugins/traffic-split.lua b/apisix/plugins/traffic-split.lua index 1d621426a137..f546225c8c95 100644 --- a/apisix/plugins/traffic-split.lua +++ b/apisix/plugins/traffic-split.lua @@ -173,6 +173,7 @@ local function set_upstream(upstream_info, ctx) key = upstream_info.key, nodes = new_nodes, timeout = upstream_info.timeout, + scheme = upstream_info.scheme } local ok, err = upstream.check_schema(up_conf) @@ -190,7 +191,9 @@ local function set_upstream(upstream_info, ctx) end core.log.info("upstream_key: ", upstream_key) upstream.set(ctx, upstream_key, ctx.conf_version, up_conf) - + if upstream_info.scheme == "https" then + upstream.set_scheme(ctx, up_conf) + end return end diff --git a/apisix/upstream.lua b/apisix/upstream.lua index 416bbea7cfa4..0ff82fea856a 100644 --- a/apisix/upstream.lua +++ b/apisix/upstream.lua @@ -175,7 +175,7 @@ local function set_upstream_scheme(ctx, upstream) ctx.var["upstream_scheme"] = ctx.upstream_scheme end - +_M.set_scheme = set_upstream_scheme local scheme_to_port = { http = 80, diff --git a/t/plugin/traffic-split2.t b/t/plugin/traffic-split2.t index 5100337e48d9..746d7441bac5 100644 --- a/t/plugin/traffic-split2.t +++ b/t/plugin/traffic-split2.t @@ -799,3 +799,66 @@ GET /t --- error_code: 500 --- error_log failed to find upstream by id: invalid-id + + + +=== TEST 21: use upstream with https scheme +--- config + location /t { + content_by_lua_block { + local json = require("toolkit.json") + local t = require("lib.test_admin") + + local data = { + uri = "/hello", + plugins = { + ["traffic-split"] = { + rules = { + { + match = { { + vars = { { "arg_scheme", "==", "https" } } + } }, + weighted_upstreams = { + { + upstream = { + type = "roundrobin", + pass_host = "node", + nodes = { + ["127.0.0.1:1983"] = 1, + }, + scheme = "https" + }, + weight = 1 + } + } + } + } + } + }, + upstream = { + type = "roundrobin", + nodes = { + ["127.0.0.1:1980"] = 1 + } + } + } + + local code, body = t.test('/apisix/admin/routes/1', + ngx.HTTP_PUT, + json.encode(data) + ) + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- response_body +passed + + + +=== TEST 22: hit route +--- request +GET /hello?scheme=https +--- error_code: 200