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

Feat/match port #5102

Merged
merged 2 commits into from
Nov 12, 2019
Merged

Feat/match port #5102

merged 2 commits into from
Nov 12, 2019

Conversation

javierguerragiraldez
Copy link
Contributor

Summary

Allow routes to specify a port in the host parameter. If present, it matches only requests to that
specific port. If absent, requests to any port matches. Requests without explicit port are handled as if they included the appropriate default port (80 for HTTP, 443 for HTTPS). Routes with port have higher priority than those that those without; even for requests without explicit port.

@javierguerragiraldez javierguerragiraldez force-pushed the feat/match-port branch 4 times, most recently from 9bdd5fb to abab7f8 Compare October 8, 2019 17:15
@hishamhm
Copy link
Contributor

hishamhm commented Oct 8, 2019

@javierguerragiraldez in the DB-less testsuite, the error happening is that with your PR the error message has changed from invalid value to invalid hostname. That test file (spec/02-integration/02-cmd/02-start_stop_spec.lua) needs to be adjusted in your PR accordingly.

@javierguerragiraldez javierguerragiraldez force-pushed the feat/match-port branch 4 times, most recently from 5e57658 to 9e1b511 Compare October 9, 2019 05:46
@javierguerragiraldez
Copy link
Contributor Author

got a clean test on the branch, but for some reason, it still fails on the (projected) merge, even if git agrees it's identical to the branch, now that it's fully squashed and rebased on next's tip.

needless to say, i couldn't get the test to fail locally, even when pulling the merge commit from github's hidden space.

@locao
Copy link
Contributor

locao commented Oct 9, 2019

@javierguerragiraldez you can safely ignore that failure. That test should be marked as flaky, the error happens because the balancer hasn't been completely created when the test runs.

@javierguerragiraldez javierguerragiraldez added this to the 1.4.0 milestone Oct 14, 2019
@hishamhm hishamhm modified the milestones: 1.4.0, 1.5.0 Oct 14, 2019
kong/db/schema/typedefs.lua Outdated Show resolved Hide resolved
Copy link
Contributor

@hutchic hutchic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read over the tests and they look correct. Please wait for and additional review / approval to merge though

@thibaultcha
Copy link
Member

I have started reviewing this change, will get back to it in a few hours, please hold the merge for now, thank you!

kong/tools/utils.lua Outdated Show resolved Hide resolved
kong/tools/utils.lua Outdated Show resolved Hide resolved
kong/tools/utils.lua Outdated Show resolved Hide resolved
kong/tools/utils.lua Outdated Show resolved Hide resolved
kong/tools/utils.lua Outdated Show resolved Hide resolved
spec/02-integration/05-proxy/02-router_spec.lua Outdated Show resolved Hide resolved
spec/01-unit/08-router_spec.lua Outdated Show resolved Hide resolved
spec/01-unit/05-utils_spec.lua Outdated Show resolved Hide resolved
kong/router.lua Outdated Show resolved Hide resolved
kong/tools/utils.lua Outdated Show resolved Hide resolved
kong/router.lua Outdated Show resolved Hide resolved
@hishamhm hishamhm removed this from the 1.5.0 milestone Nov 5, 2019
kong/db/schema/typedefs.lua Outdated Show resolved Hide resolved
kong/router.lua Outdated Show resolved Hide resolved
kong/router.lua Outdated Show resolved Hide resolved
kong/router.lua Outdated Show resolved Hide resolved
kong/router.lua Outdated Show resolved Hide resolved
Allow routes to specify a port in the host parameter. If present, it
matches only requests to that specific port. If absent, requests to
any port matches. Requests without explicit port are handled as if
they included the appropriate default port (80 for HTTP, 443 for
HTTPS). Routes with port have higher priority than those that those
without; even for requests without explicit port.
@thibaultcha
Copy link
Member

Please hold before merging, thanks!

assert.same(nil, match_t.matches.method)
assert.same(nil, match_t.matches.uri)
assert.same(nil, match_t.matches.uri_captures)
end)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was covered in a few test case, but a bit too indirectly, and I'm afraid the test may be updated in the future and not cover the case, so here is an isolated test case specifically for the submatching priority.

@@ -770,8 +774,7 @@ do
local matchers = {
[MATCH_RULES.HOST] = function(route_t, ctx)
local req_host = ctx.hits.host or ctx.req_host
local host = route_t.hosts[req_host]
or route_t.hosts[split_port(req_host)]
local host = route_t.hosts[req_host] or route_t.hosts[ctx.host_no_port]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my last remaining concern: I removed the call to split_port on this hot path, without any issues so far storing host_no_port in the context.

HAS_HOST_PORT = 0x04,
HAS_REGEX_URI = 0x01,
PLAIN_HOSTS_ONLY = 0x02,
HAS_WILDCARD_HOST_PORT = 0x04,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed this submatching rule to be more precise: we only case about it when dealing with regex hosts.

@thibaultcha thibaultcha merged commit 470578c into next Nov 12, 2019
@thibaultcha thibaultcha deleted the feat/match-port branch November 12, 2019 01:31
hutchic pushed a commit that referenced this pull request Nov 21, 2019
Allow routes to specify a port in the host parameter. If present, it
matches only requests to that specific port. If absent, requests to
any port will match. Requests without explicit port are handled as if
they included the appropriate default port (80 for HTTP, 443 for
HTTPs). Routes with a port have higher priority than those without;
even for requests without an explicit port in the Host header.

From #5102
bungle added a commit that referenced this pull request Dec 9, 2019
### Summary

PR #5102 changed service entity where it added optional `port` to
`service.host`. This is not actually used, and is wrong as the service
also has `service.port` for that. Thus this PR returns that back to
original, that is `service.host` cannot contain `port`.
hishamhm pushed a commit that referenced this pull request Dec 10, 2019
### Summary

PR #5102 changed service entity where it added optional `port` to
`service.host`. This is not actually used, and is wrong as the service
also has `service.port` for that. Thus this PR returns that back to
original, that is `service.host` cannot contain `port`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants