Need a way to get the url submitted to a InternalRedirect

guest avatarguest created an issue

To get the complete URL (with parameters) was broken when a Internal Redirect was raised. It does not happen very often, but in some places one internal redirect raises another internal redirect.

In each of the above case I need to get the full url (including parameters) of the last internal redirect request.

I made the changes by editing:

_cprequest.__init__: add self.redirectionsIr = []

_cprequest.run: change self.redirections.append(pi) to

     self.redirections.append(pi)
     self.redirectionsIr.append(ir.origPath)

Then anywhere in my application I do the following to get the current page url:

if cherrypy.request.redirectionsIr:
    context.currentPageUrl = urllib.quote(cherrypy.request.redirectionsIr[-1])
else:
    context.currentPageUrl = urllib.quote(cherrypy.request.browser_url)

Comments (5)

  1. Robert Brewer

    I'd like to suggest the attached patch to fix this in CP 3. It's a more drastic change than I'd like at this late date, but I think it's necessary in order to support internal redirects fully. It does the following:

    1. Given an original URL1 and redirections to URL2 and URL3, the patch will set request.redirections to [URL1, URL2] and request.path_info to URL 3. Current trunk leaves path_info at URL1 and sets request.redirections to [URL2, URL3] (but schizophrenically changes request.query_string each time). 2. The patch adds request.path_info + request.query_string to form the URLs it saves in request.redirections. Current trunk only saves path_info. 3. The current trunk tried to make cherrypy.url() return the URL in the client's browser even if redirected internally. In order to recall querystrings (and meet more diverse needs such as tools.caching), the patch would make cherrypy.url() return the redirected URL; it puts the burden on redirection targets to call cherrypy.url(path=request.redirections[0]) if they need the original URL.

  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.