How to utilize Catch All, Empty Placeholders, Priority routing features correctly since v23+? #2136
-
BugSince release v23+, the Catch All functionality seems to be broken on sub-paths. Absolute routes no longer match over catch-all ones. Screenshot 1 works as intended, Screenshot 2 does not. Expected behavior (Screenshot 1):
Actual behavior (Screenshot 1):
Expected behavior (Screenshot 2):
Actual behavior (Screenshot 2):
Specifications
|
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 6 replies
-
This seems to also happen with multiple levels of catch all Ocelot: "Routes": [
{
"UpstreamHttpMethod": [ "Get" ],
"UpstreamPathTemplate": "/test/{url}/{url2}",
"DownstreamPathTemplate": "/generic/{url}/{url2}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 8000
}
]
},
{
"UpstreamHttpMethod": [ "Get" ],
"UpstreamPathTemplate": "/test/{url}",
"DownstreamPathTemplate": "/specific/{url}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 8000
}
]
}
],
"GlobalConfiguration": {
"BaseUrl": "https://localhost:5000"
} Only |
Beta Was this translation helpful? Give feedback.
-
Hello Sims!
Actually, the functionality was "broken"/changed specifically in version 23.0.0 as seen in the commit f4803c2.
Understood. However, it's important to note that the two screenshots pertain to distinct features. Additional details follow.
Correct! It is connected to PR #1911. While #748 was initially closed with the bug fix in #1911, it turns out that #748 contains new functionality requirements, making #1911 a feature PR rather than a simple bug fix. |
Beta Was this translation helpful? Give feedback.
-
The screenshot and user scenario depicted precisely illustrate the Catch All Routing feature. It is operational and continues to function in version 23.3. Perfect! |
Beta Was this translation helpful? Give feedback.
-
Hi @raman-m, I'm a little confused by your response. Is this a bug or am i not using the features of Ocelot correctly?
So is the catch-all feature only supposed to be used for the root path? Can you link me the documentation for a similar feature for a catch-all on subpaths? Also, am i correct to think that the input url that matches the upstream template more closely should be taken, rather than a priority from first to last? (Otherwise you'd be unable to create more advanced routing definitions) Another question, can i disable the feature that's causing this as a temporary workaround? |
Beta Was this translation helpful? Give feedback.
-
The "Screenshot 2" user scenario pertains to the Empty Placeholders feature. Both upstream templates Subsequently, the foreach loop iterates over all the applicable routes and generates a new list of downstream routes:However, since the Priority feature is not employed, the first route in the list is selected by default. Additionally, it can be said that the Actual behavior is derived from the Empty Placeholders feature. Conversely, the Expected behavior is a result of the Priority feature. To achieve the expected behavior, one must employ the Priority routing feature, which is specifically designed for scenarios with implicit or unclear route priorities. |
Beta Was this translation helpful? Give feedback.
-
For #2136 (comment), it's impossible to use priority to solve this. The first match will always swallow the entire url. |
Beta Was this translation helpful? Give feedback.
-
I understand your interest in software testing, but what is the purpose of such detailed analysis? Both
Indeed, the URL matches the second route template because it does not have two subpaths required to match the first route. Bingo!
Indeed, the URLs All behavior is correct! There are no issues. However, there seems to be a lack of clarity regarding the Routing feature, which warrants a second reading by you. Experimenting with subpaths while disregarding the existing, ready-to-use features is nonsensical. Such experiments often lead to confusion and are prone to failure. It's advisable to fully utilize the power of the already implemented Routing features before attempting to develop more customized solutions on top of the existing functionality. |
Beta Was this translation helpful? Give feedback.
-
I haven't had the time to verify the accuracy of the statement, but it appears everything is detailed in my #2136 (comment). "Routes": [
{
"UpstreamPathTemplate": "/generic/{url}/{url2}",
"DownstreamPathTemplate": "/generic/{url}/{url2}",
},
{
"UpstreamPathTemplate": "/specific/{url}",
"DownstreamPathTemplate": "/specific/{url}",
}
],
"GlobalConfiguration": {
"BaseUrl": "https://localhost:5000"
} This solution is elegant and avoids the need for debates with the product owner. 😉 |
Beta Was this translation helpful? Give feedback.
@suchmememanyskill wrote
I haven't had the time to verify the accuracy of the statement, but it appears everything is detailed in my #2136 (comment).
Priorities are only sensible for applicable routes! In this instance, since the routes differ and each URL has just one applicable route, the Priority feature becomes redundant. Correct? Thus, for this scenario, you would need to use a different upstream path prefix, and a possible solution could be as follows: