I am having a problem with HTTPRedirects from a default handler. Here's my setup. I have a class called class called StudentController which is sitting on my root handler under 'students'. All requests are going to a default handler, which under certain circumstances will redirect to another page which is also handled by this default handler. The problem is that when I redirect, it takes me back to the root of the site.
For instance, the user first requests /students/. This raises an HTTPRedirect to 'contact'. However, instead of taking the user to /students/contact like I would expect it to, they are redirected to /contact. I have tracked this problem down to the url function in __init__.py. Apparently this function will automatically strip a trailing slash from the current url if the call is not being handled by an index function, which it isn't because its a default handler. This causes the result of cherrypy.url (which is called in the HTTPRedirect __init__ function) to return /students (note the lack of a trailing slash). _urljoin then removes the 'students' part of the url, and the end url is /contact.
Basically, I know exactly what the problem is and what is causing it, but my question is whether or not this is supposed to happen. I'm considering filing a bug regarding this, but I wanted to check first that this isn't the desired behavior.
The way I consider fixing this issue is to make a default handler set the is_index attribute on a request. This would make cherrypy.url keep the trailing slash so that the redirect would work correctly.
I can write a patch to do this, I just need to make sure that this is a bug.
ethilien wrote: > I am having a problem with HTTPRedirects from a default handler. Here's > my setup. I have a class called class called StudentController which is > sitting on my root handler under 'students'. All requests are going to > a default handler, which under certain circumstances will redirect to > another page which is also handled by this default handler. The problem > is that when I redirect, it takes me back to the root of the site.
> For instance, the user first requests /students/. This raises an > HTTPRedirect to 'contact'. However, instead of taking the user to > /students/contact like I would expect it to, they are redirected to > /contact. I have tracked this problem down to the url function in > __init__.py. Apparently this function will automatically strip a > trailing slash from the current url if the call is not being handled by > an index function, which it isn't because its a default handler. This > causes the result of cherrypy.url (which is called in the HTTPRedirect > __init__ function) to return /students (note the lack of a trailing > slash). _urljoin then removes the 'students' part of the url, and the > end url is /contact.
> Basically, I know exactly what the problem is and what is causing it, > but my question is whether or not this is supposed to happen. I'm > considering filing a bug regarding this, but I wanted to check first > that this isn't the desired behavior.
> The way I consider fixing this issue is to make a default handler set > the is_index attribute on a request. This would make cherrypy.url keep > the trailing slash so that the redirect would work correctly.
> I can write a patch to do this, I just need to make sure that this is a > bug.
This looks like a bug to me. A ticket would be great!
Robert Brewer System Architect Amor Ministries fuman...@amor.org
Hmm, maybe I'm just being dumb and can't find it, but I can't figure out how to create an account in the trac to submit a ticket. I keep just getting permission denied errors when I go to the newticket page...
> ethilien wrote: > > I am having a problem with HTTPRedirects from a default handler. Here's > > my setup. I have a class called class called StudentController which is > > sitting on my root handler under 'students'. All requests are going to > > a default handler, which under certain circumstances will redirect to > > another page which is also handled by this default handler. The problem > > is that when I redirect, it takes me back to the root of the site.
> > For instance, the user first requests /students/. This raises an > > HTTPRedirect to 'contact'. However, instead of taking the user to > > /students/contact like I would expect it to, they are redirected to > > /contact. I have tracked this problem down to the url function in > > __init__.py. Apparently this function will automatically strip a > > trailing slash from the current url if the call is not being handled by > > an index function, which it isn't because its a default handler. This > > causes the result of cherrypy.url (which is called in the HTTPRedirect > > __init__ function) to return /students (note the lack of a trailing > > slash). _urljoin then removes the 'students' part of the url, and the > > end url is /contact.
> > Basically, I know exactly what the problem is and what is causing it, > > but my question is whether or not this is supposed to happen. I'm > > considering filing a bug regarding this, but I wanted to check first > > that this isn't the desired behavior.
> > The way I consider fixing this issue is to make a default handler set > > the is_index attribute on a request. This would make cherrypy.url keep > > the trailing slash so that the redirect would work correctly.
> > I can write a patch to do this, I just need to make sure that this is a > > bug.
> This looks like a bug to me. A ticket would be great!
> Robert Brewer > System Architect > Amor Ministries > fuman...@amor.org
On 12/1/06, Connor McKay <ethil...@gmail.com> wrote:
> Hmm, maybe I'm just being dumb and can't find it, but I can't figure out > how to create an account in the trac to submit a ticket. I keep just getting > permission denied errors when I go to the newticket page...
> On 12/1/06, Connor McKay <ethil...@gmail.com> wrote:
> > Hmm, maybe I'm just being dumb and can't find it, but I can't figure out > > how to create an account in the trac to submit a ticket. I keep just getting > > permission denied errors when I go to the newticket page...