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

Better API for matching query params #7

Open
chrisk opened this issue Oct 31, 2009 · 1 comment
Open

Better API for matching query params #7

chrisk opened this issue Oct 31, 2009 · 1 comment

Comments

@chrisk
Copy link
Owner

chrisk commented Oct 31, 2009

Right now, the query params of the incoming request are sorted by key before we try to match against all the registered Regexps and URI objects. This works fine for URIs, because we can sort those query params too, so the user doesn't even know.

For Regexps, though, it seems impossible to figure out what part of the Regexp represents the query params and sort it; so the user has to be aware that their Regexp must be written to match against sorted params. That can be kind of hard sometimes. For example, a registration might look something like:

/example\.com\?[z\d]{2}=1&(opt1=a|opt2=b)$/

To match this URI:

http://example.com?9z=1&opt2=b

But also this URI:

http://example.com?zz=1&opt1=a

So you can see that if we sorted the second URI's params by key, it wouldn't match the Regexp. Instead, the user would have to register a Regexp that matches either order (or do two register_uri calls), which is pretty ugly.

We tried getting around this by calculating all the possible orders of the params and matching them, but that's O(n!) and therefore intractable for even pretty reasonable query params counts.

So the idea is that we could add a new API entirely, and get the query params out of the Regexp. Maybe an additional argument to register_uri with a hash of params that must in the request?

(Forked from issue #5.)

@akahn
Copy link
Contributor

akahn commented Dec 17, 2009

I think a new API, and no longer matching query params with Regexp is a good idea. A hash of params (as mentioned by mbleigh in #5) would be ideal.

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

No branches or pull requests

2 participants