Skip to content

Commit

Permalink
fix(router): add missing preserve_host logic in stream subsystem (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Mar 4, 2024
1 parent d04991f commit bed2a9e
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 11 deletions.
5 changes: 5 additions & 0 deletions kong/router/atc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,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.com" },
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.com" },
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.com" },
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 @@ -31,6 +31,7 @@ do

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

0 comments on commit bed2a9e

Please sign in to comment.