Skip to content

Commit

Permalink
feat: traffic-split plugin support https (#9115)
Browse files Browse the repository at this point in the history
  • Loading branch information
TenYearsIn authored Sep 27, 2023
1 parent ddac444 commit 869754b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
5 changes: 4 additions & 1 deletion apisix/plugins/traffic-split.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion apisix/upstream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
63 changes: 63 additions & 0 deletions t/plugin/traffic-split2.t
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 869754b

Please sign in to comment.