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

conflict between 2 routes that shouldn't happen ? #175

Closed
tjannaud opened this issue Jan 2, 2017 · 2 comments
Closed

conflict between 2 routes that shouldn't happen ? #175

tjannaud opened this issue Jan 2, 2017 · 2 comments
Labels

Comments

@tjannaud
Copy link

tjannaud commented Jan 2, 2017

hi
I have routes:

"/v1/a/:name"
"/v1/a/user/selection"

since :name doesn't match / these 2 routes should not conflict but they do. Can you confirm?

@julienschmidt
Copy link
Owner

Unfortunately this is correct, which is one of the drawbacks of prefix matching like tries (aka. prefix trees) perform it.

After the prefix /v1/a/ it can not tell if :name or user should be chosen. The router does not have a "global view", i.e. it does not know all possible sub-routes without actually trying them.
The only ways to to resolve this is to either let "static" segments like user always have preference over dynamic ones like :name, which is currently the plan for v2, or perform backtracking.
Backtracking means trying one route and if it can not be matches go up the tree again and try the alternative route. However, this makes the behavior of the router a lot less obvious and the routing more complex, e.g. it requires that nodes have knowledge of the parent node, which is currently not the case. The much bigger question is however, in which order the routes should be tried.

The design decisions for the current version was, that at any time a URL path can match at most one route. Thus, it is illegal to register /v1/a/:name and /v1/a/user at the same time, regardless of /v1/a/user being only used as a prefix for the actual route /v1/a/user/selection. To resolve it, register /v1/a/:name/selection instead and manually make sure that :name has the value "user" in the handler of the route.

@tjannaud
Copy link
Author

tjannaud commented Jan 9, 2017

Thanks for the /v1/a/:name/selection tip

suzuki-shunsuke added a commit to suzuki-shunsuke/go-graylog that referenced this issue Aug 4, 2018
httprouter's pattern matching is difficult.

julienschmidt/httprouter#175
suzuki-shunsuke added a commit to suzuki-shunsuke/go-graylog that referenced this issue Aug 4, 2018
httprouter's pattern matching is difficult.

julienschmidt/httprouter#175
suzuki-shunsuke added a commit to suzuki-shunsuke/go-graylog that referenced this issue Aug 4, 2018
httprouter's pattern matching is difficult.

julienschmidt/httprouter#175
similark pushed a commit to similarweb/httprouter that referenced this issue May 9, 2023
Also adding slightly more explanation about the chart and
relevant HTTPScaledObject

Signed-off-by: Aaron Schlesinger <aaron@ecomaz.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants