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(router): add preserve_host logic in stream subsystem #12261

Merged
merged 10 commits into from
Dec 29, 2023
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
5 changes: 5 additions & 0 deletions kong/router/atc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,11 @@ function _M:exec(ctx)

else
route_match_stat(ctx, "pos")

-- preserve_host logic, modify cache result
if match_t.route.preserve_host then
match_t.upstream_host = fields.get_value("tls.sni", CACHE_PARAMS)
end
end

return match_t
Expand Down
21 changes: 14 additions & 7 deletions kong/router/fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,20 @@ if is_http then
end -- is_http


local function fields_visitor(fields, params, ctx, cb)
for _, field in ipairs(fields) do
local func = FIELDS_FUNCS[field]
local function get_value(field, params, ctx)
local func = FIELDS_FUNCS[field]

if not func then -- unknown field
error("unknown router matching schema field: " .. field)
end -- if func

return func(params, ctx)
end

if not func then -- unknown field
error("unknown router matching schema field: " .. field)
end -- if func

local value = func(params, ctx)
local function fields_visitor(fields, params, ctx, cb)
for _, field in ipairs(fields) do
local value = get_value(field, params, ctx)

local res, err = cb(field, value)
if not res then
Expand Down Expand Up @@ -352,6 +357,8 @@ end


return {
get_value = get_value,

get_cache_key = get_cache_key,
fill_atc_context = fill_atc_context,

Expand Down
1 change: 1 addition & 0 deletions spec/02-integration/01-helpers/01-helpers_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ for _, strategy in helpers.each_strategy() do
bp.routes:insert {
hosts = { "mock_upstream" },
protocols = { "http" },
paths = { "/" },
service = service
}

Expand Down
10 changes: 6 additions & 4 deletions spec/02-integration/05-proxy/02-router_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -877,15 +877,16 @@ for _, strategy in helpers.each_strategy() do
describe("URI arguments (querystring)", function()
local routes

before_each(function()
lazy_setup(function()
routes = insert_routes(bp, {
{
hosts = { "mock_upstream" },
paths = { "/" },
},
})
end)

after_each(function()
lazy_teardown(function()
remove_routes(strategy, routes)
end)

Expand Down Expand Up @@ -1301,6 +1302,7 @@ for _, strategy in helpers.each_strategy() do
routes = insert_routes(bp, {
{
protocols = { "https" },
paths = { "/" },
snis = { "www.example.org" },
service = {
name = "service_behind_www.example.org"
Expand Down Expand Up @@ -1343,7 +1345,7 @@ for _, strategy in helpers.each_strategy() do
path = "/status/201",
headers = { ["kong-debug"] = 1 },
})
assert.res_status(flavor == "traditional" and 201 or 200, res)
assert.res_status(201, res)
assert.equal("service_behind_www.example.org",
res.headers["kong-service-name"])

Expand All @@ -1365,7 +1367,7 @@ for _, strategy in helpers.each_strategy() do
path = "/status/201",
headers = { ["kong-debug"] = 1 },
})
assert.res_status(flavor == "traditional" and 201 or 200, res)
assert.res_status(201, res)
assert.equal("service_behind_example.org",
res.headers["kong-service-name"])
end)
Expand Down
1 change: 1 addition & 0 deletions spec/02-integration/05-proxy/03-upstream_headers_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ for _, strategy in helpers.each_strategy() do

assert(bp.routes:insert {
hosts = { "headers-charset.test" },
paths = { "/" },
service = service,
})

Expand Down
1 change: 1 addition & 0 deletions spec/02-integration/05-proxy/14-server_tokens_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ describe("headers [#" .. strategy .. "]", function()
return function()
bp.routes:insert {
hosts = { "headers-inspect.test" },
paths = { "/" },
}

local service = bp.services:insert({
Expand Down
1 change: 1 addition & 0 deletions spec/03-plugins/07-loggly/01-log_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ for _, strategy in helpers.each_strategy() do

local route1 = bp.routes:insert {
hosts = { "logging.test" },
paths = { "/" },
}

local route2 = bp.routes:insert {
Expand Down
1 change: 1 addition & 0 deletions spec/03-plugins/25-oauth2/04-invalidations_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ for _, strategy in helpers.each_strategy() do
route = assert(admin_api.routes:insert {
hosts = { "oauth2.com" },
protocols = { "http", "https" },
paths = { "/" },
service = service,
})

Expand Down
1 change: 1 addition & 0 deletions spec/03-plugins/31-proxy-cache/02-access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ do

local route1 = assert(bp.routes:insert {
hosts = { "route-1.test" },
paths = { "/" },
})
local route2 = assert(bp.routes:insert {
hosts = { "route-2.test" },
Expand Down
Loading