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

Prefix wildcard matching is required #18

Closed
rakyll opened this issue Mar 5, 2018 · 1 comment · Fixed by #19
Closed

Prefix wildcard matching is required #18

rakyll opened this issue Mar 5, 2018 · 1 comment · Fixed by #19
Assignees

Comments

@rakyll
Copy link
Contributor

rakyll commented Mar 5, 2018

Currently, govanityurls looks for an exact prefix match for the paths provided in the configuration file.

host: my.org

paths:
   - /example/helloworld
        repo: ....
   - /
        repo: .... 

If user asks for my.org/x, govanityurls return a 404 instead of matching it with the second rule.

What's expected is that we should match /x with the / rule.

@rakyll rakyll self-assigned this Mar 5, 2018
@odeke-em
Copy link

odeke-em commented Mar 8, 2018

I once encountered this problem when deciding the most appropriate matching paths and directories to serve for a cloud service during cache misses based off their prefix.

I recall the algorithm that I used, it seems simple enough to find the most common prefix i.e.:

  • Given rules/paths H
  • Given a query Q
  • Sort H by length of each element -- for fast exact search using binary search
  1. Search for the queried rule with a binary search over H. If we can find it, return it, else goto 2.
  2. We need to match the closest/shortest prefix relative to the query. For a prefix, we need len(rule) < len(Q), giving us items pR
  3. For each pRi in pR, trim it from Q, recording the length and pRI if shorter than known
  4. The shortest trimmed remainder from TrimPrefix(Q, pRi) is the closest host

With some runnable code at https://gist.github.com/odeke-em/4101fc01adaea3bfead1241e561fcc61, it can further be optimized but that serves the purpose I believe.

odeke-em added a commit to orijtech/govanityurls that referenced this issue Mar 9, 2018
Fixes GoogleCloudPlatform#18

If any pathConfig is the shortest prefix of a query,
find and return it.

For example:
* PathConfigs: {"/example/helloworld", "/example", "/", "/x"}

Query|Result
---|---
"/example/helloworld/foo"|"/example/helloworld"
"/foo"|"/"
"/y"|"/"
"foo"|""
"/y/x"|""
"/x/y"|"/x"
odeke-em added a commit to orijtech/govanityurls that referenced this issue Mar 9, 2018
Fixes GoogleCloudPlatform#18

If any pathConfig is the shortest prefix of a query,
find and return it.

For example:
* PathConfigs: {"/example/helloworld", "/example", "/", "/x"}

Query|Result
---|---
"/example/helloworld/foo"|"/example/helloworld"
"/foo"|"/"
"/y"|"/"
"foo"|""
"/y/x"|"/"
"/x/y"|"/x"
rakyll pushed a commit that referenced this issue Mar 15, 2018
…route is found (#19)

Fixes #18

If any pathConfig is the shortest prefix of a query,
find and return it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants