Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #584 (defect)

Opened 2 years ago

Last modified 2 years ago

Need a way to get the url submitted to a InternalRedirect

Status: closed (fixed)

Reported by: guest Assigned to: fumanchu
Priority: normal Milestone: 3.0
Component: CherryPy code Keywords:
Cc:

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)

Attachments

iredir.patch (4.9 kB) - added by fumanchu on 10/16/06 00:33:43.
Patch to InternalRedirect? which saves each path_info+qs

Change History

10/15/06 20:48:29: Modified by fumanchu

  • description changed.

10/16/06 00:33:43: Modified by fumanchu

  • attachment iredir.patch added.

Patch to InternalRedirect? which saves each path_info+qs

10/16/06 00:47:47: Modified by fumanchu

  • owner changed from rdelon to fumanchu.
  • status changed from new to assigned.

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.

10/19/06 01:27:16: Modified by fumanchu

  • status changed from assigned to closed.
  • resolution set to fixed.

Applied to trunk in 1400.

Hosted by WebFaction

Log in as guest/cpguest to create tickets