AW: [Zope3-Users] "raise Redir(newurl)" not working - can someoneconfirm this?

Hermann Himmelbauer dusty at qwer.tk
Sat Apr 19 11:17:13 EDT 2008


Am Samstag, 19. April 2008 14:05 schrieb Roger Ineichen:
> Hi Hermann
>
> > Betreff: [Zope3-Users] "raise Redir(newurl)" not working -
> > can someoneconfirm this?
> >
> > Hi,
> > In my application, namely for URL-Rewriting for session
> > handling, I need to stop the current request and redirect to
> > another url (including the session key).
> >
> > For that reason, I issue the following statement:
> >
> > from zope.publisher.interfaces import Redirect raise
> > Redirect('http://my.new.url')
>
> I always use self.request.response.redirect(url)

I normally do, too. But in this special case, it must not happen that some 
later code calls self.request.response.redirect() and therefore overwrites my 
redirect.

Due to the problems with the Render exception, I experimented with 
self.request.response.redirect() and it seems to be overwritten, which leads 
in some way I don't fully understand to endless recursions/redirecting.

However, this endless recursion has something to do with virtual hosts; 
Something smells fishy there, too, as application names are not added to 
request._app_names if ++vh++ is specified at the URL, instead, namespaces 
like "++lang++" etc. remain in request._traversed_names.

One can easily see this by inserting something like this in his view code:

print request.getTraversalStack()
print request._traversed_names
print request._app_names

And then by accessing a site directly and via a virtual host (e.g. Zope3 
behind Apache) and comparing the values. (Something 
like "++skin++" / "++lang++" should be in the URL to see it.)

Either there is something buggy in Zope3/virtual hosts or things happen which 
I don't understand...

> > /++session++VLdODjCYl90YmQwdNG6hvdiT11UZS3oly5kXonWYLHdGHloxvT
> > shQs/favicon.ico
> > --------------
>
> Are you trying to redirect to the favicon.ico?

No, my case is quite simple: Mobile phones have only limited/buggy cookie 
support, therefore I rewrite the URL and store a session key there (as shown 
above). What I did is to simply create my ClientIdManager, which inherits 
from CookieClientIdManager, where I overwrote the getClientId() method.

> > I don't know why this happens, *maybe* that's due to
> > inclusion of some 3rd party packages, e.g. z3c.layer.pagelet?
> >
> > To confirm this, I'd like to know if this scenario is only
> > happening for me, so, can you please simply insert the above
> > statement in some arbitrary view and tell me if it works?
>
> I'm not 100% sure but,
>
> Note, if you use redirect you have to take care when you
> are doing this. You can only do this in the view call
> but not if the pagelet renders the template, because that's
> too late. This is not pagelet specific, that's also the case
> if you render a template in a BrowserPage?

Well, I do this very early, namely in the ClientIdManager, that's I think 
before pages are rendered. But, perhaps, that's too early?

Best Regards,
Hermann

-- 
hermann at qwer.tk
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7


More information about the Zope3-users mailing list