-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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) wildcard host matching not considered with plain host match #4152
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -512,7 +512,8 @@ end | |
do | ||
local matchers = { | ||
[MATCH_RULES.HOST] = function(route_t, ctx) | ||
local host = route_t.hosts[ctx.hits.host or ctx.req_host] | ||
local host = route_t.hosts[ctx.req_host] or | ||
route_t.hosts[ctx.hits.host] | ||
if host then | ||
ctx.matches.host = host | ||
|
||
|
@@ -705,7 +706,8 @@ end | |
do | ||
local reducers = { | ||
[MATCH_RULES.HOST] = function(category, ctx) | ||
return category.routes_by_hosts[ctx.hits.host] | ||
return category.routes_by_hosts[ctx.req_host] or | ||
category.routes_by_hosts[ctx.hits.host] | ||
end, | ||
|
||
[MATCH_RULES.URI] = function(category, ctx) | ||
|
@@ -986,23 +988,24 @@ function _M.new(routes) | |
|
||
-- host match | ||
|
||
if plain_indexes.hosts[ctx.req_host] then | ||
req_category = bor(req_category, MATCH_RULES.HOST) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change can be highly detrimental in many scenarios. |
||
|
||
elseif ctx.req_host then | ||
do | ||
local wildcard_match, _, err | ||
for i = 1, #wildcard_hosts do | ||
local from, _, err = re_find(ctx.req_host, wildcard_hosts[i].regex, "ajo") | ||
wildcard_match, _, err = re_find(ctx.req_host, wildcard_hosts[i].regex, "ajo") | ||
if err then | ||
log(ERR, "could not match wildcard host: ", err) | ||
return | ||
end | ||
|
||
if from then | ||
hits.host = wildcard_hosts[i].value | ||
req_category = bor(req_category, MATCH_RULES.HOST) | ||
if wildcard_match then | ||
hits.host = wildcard_hosts[i].value | ||
break | ||
end | ||
end | ||
|
||
if wildcard_match or plain_indexes.hosts[ctx.req_host] then | ||
req_category = bor(req_category, MATCH_RULES.HOST) | ||
end | ||
end | ||
|
||
-- uri match | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we are ignoring the matched hint, which is thus rendered useless. In which case we could simply remove it. This change can be detrimental in some scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? If you remove
route_t.hosts[ctx.hits.host]
the tests will not pass, and if you removeroute_t.hosts[ctx.req_host]
the tests won't pass either. So it is not ignored (?).