-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(router) ensure regex path always takes precedence over plain path
This is the third commit of a series of fixes to the router. Background ---------- As established a couple of commits ago, the rules for routing priorities are: 1. Routes with more matching attributes take precedence over Routes with fewer matching attributes 2. Plain hosts take precedence over wildcard hosts 3. Regex path always takes precedence over plain paths 4. Longer plain paths take precedence over shorter plain paths **Note:** as of today, our documentation is not reflecting the router's behavior. As of July 3rd, 2019, the proxy guide (https://docs.konghq.com/1.2.x/proxy/#evaluation-order) states that plain paths are evaluated before regex paths, and implies that the former have priority over the latter, which is not correct as per the router behavior, and asserted as per a series of established test cases. As per the above rules, consider the following simplified scenario: r1: paths = { "/pat" } r2: paths = { "/(path)" } local matched_route = router.select("GET", "/path", "route.com") -- matched_route == r2 Issue ----- Now, consider the following scenario: r1: paths = { "/pat" } hosts = { "route.com" } r2: paths = { "/(path)" } hosts = { "route.com" } local matched_route = router.select("GET", "/path", "route.com") -- /!\ matched_route should still be r2, but prior to this patch, was r1 The above case highlights a flaw in the router: that categorized Routes are not sorted as per rules 2., 3., and 4. (aforementioned). This would not be an issue if regex paths and wildcard hosts were matching categories of their own, but for historical reasons, they are not, at least at the moment. Note: said reasons include the lack of dynamic categories lists support in the initial router implementation, something that was fixed in 1ba8ab2 prior to the introduction of SNI/src/dst routing. This is outside the scope of this patch. Therefore, this patch ensures that all categorized Routes are thus sorted appropriately relative to each other within their respective categories. Note ---- It is worth noting that this patch can be breaking in its nature, given that the router behavior highlighted by the new test will differ before and after the patch. This patch replaces the one in #4153, which is more expensive and relies on indexes to fix the issue, instead of fixing the ordering. It was also lacking unit tests, which are more appropriate (and mandatory) for router changes. Replaces #4153
- Loading branch information
1 parent
73a57a5
commit 2683b86
Showing
3 changed files
with
138 additions
and
25 deletions.
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
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
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