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

Support some sort of URL rewriting in Drapache #2

Open
gnrfan opened this issue May 27, 2012 · 3 comments
Open

Support some sort of URL rewriting in Drapache #2

gnrfan opened this issue May 27, 2012 · 3 comments

Comments

@gnrfan
Copy link

gnrfan commented May 27, 2012

A simple URL rewriting mechanism would be very very welcomed. The good news is it's perfectly safe to add URL rewriting to Drapache and I will surely enable certain kinds of apps and scripts to be much more easily written this way.

Something with all of the power of mod_rewrite in Apache would be cool but I guess we don't need it since we got Python, right?

How about redirecting all 404s to a top level _rewrite.dbpy script if it's present?

Once you have that you would only need to provide us with a way to read the original requested path and we can put together our own pattern matching and URL rewriting mechanism.

Here's some code sample to help illustrate the idea:

import re

request = dbpy.http.get_request()

m = re.compile('^/posts/(?P<post_id>\d+)$')

if m.matches(request.redirect_uri):
post_id = m.groupdict()['post_id']
dbpy.http.redirect('/read_post.dbpy?post_id=%d' % post_id)

@louissobel
Copy link
Owner

hey @gnrfan, this is a good idea. i definitely agree that routing is something that its missing, and I was working on a possible implementation when I released it.

my idea was to have one dbpy file, and then the requested path as a query parameter,

So that one file will get executed every time, and it knows what route the user is trying to get.

the idea of the 404 exception handler is a really cool one though, the downside is an unnecessary request to dropbox.
it would have to be implemented at a high level in the request, probably in dbserver.py. There is a catch block there that catches a dropbox ErrorResponse. That's where 404s originate, so that's where they could be caught.

@gnrfan
Copy link
Author

gnrfan commented May 30, 2012

Sounds good. How about having both mechanisms and making the completely optional? I'd say they could be placed in the top level of the folder and be called _router.dbpy and _notfound.dbpy respectively.

@gnrfan
Copy link
Author

gnrfan commented May 30, 2012

Something to work out with both would be a way to directly dispatch the re-routed request from the server side without sending a redirection response to the client.

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