Issue #584 resolved

Need a way to get the url submitted to a InternalRedirect

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 = []}}}

{{{}}}: 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