POST data with index() called as default method

101 views
Skip to first unread message

Alexander Marks

unread,
Aug 29, 2008, 6:22:52 PM8/29/08
to cherrypy-users
I've found that POST data is not passed through when submitted to an
index() method which was called as the default method for a path. GET
always works, and POST works when index() is called explicitly, ie:

http://app -- doesn't receive POST
http://app/index -- does receive POST

Is there a reason for this behavior that I missed in the
documentation?

Alexander

Jason Earl

unread,
Aug 29, 2008, 8:05:48 PM8/29/08
to cherryp...@googlegroups.com
Alexander Marks <aom...@gmail.com> writes:

I don't know how well documented it is, but

http://hostname/app

and

http://hostname/app/

are not quite the same thing. The first is should call the "app" method
on your root object and the second should call the "index" method on the
app object.

By default cherrypy has the tools.trailing_slash tool on,
which would redirect from http://hostname/app to http://hostname/app/ if
the trailing slash is missing after an index handler, but that doesn't
help you much for POSTs.

On the bright side you can post to http://hostname/app/ and it will work
just like http://hostname/app/index

I hope this was helpful.

Jason

Alexander Marks

unread,
Aug 29, 2008, 9:03:45 PM8/29/08
to cherrypy-users
As you suggested, the trailing slash is the culprit. This doesn't
work:

http://hostname/app

But these all do:

http://hostname/app/
http://hostname/app/index
http://hostname/app/index/

Why does the last case work -- which also redirects with a 303 -- but
not the first?

Alexander

On Aug 29, 5:05 pm, Jason Earl <je...@xmission.com> wrote:
> Alexander Marks <aoma...@gmail.com> writes:
> > I've found that POST data is not passed through when submitted to an
> > index() method which was called as the default method for a path. GET
> > always works, and POST works when index() is called explicitly, ie:
>
> >http://app-- doesn't receive POST
> >http://app/index-- does receive POST
>
> > Is there a reason for this behavior that I missed in the
> > documentation?
>
> > Alexander
>
> I don't know how well documented it is, but
>
> http://hostname/app
>
> and
>
> http://hostname/app/
>
> are not quite the same thing.  The first is should call the "app" method
> on your root object and the second should call the "index" method on the
> app object.
>
> By default cherrypy has the tools.trailing_slash tool on,
> which would redirect fromhttp://hostname/apptohttp://hostname/app/if
> the trailing slash is missing after an index handler, but that doesn't
> help you much for POSTs.
>
> On the bright side you can post tohttp://hostname/app/and it will work
> just likehttp://hostname/app/index

Robert Brewer

unread,
Aug 30, 2008, 12:54:00 PM8/30/08
to cherryp...@googlegroups.com
Alexander Marks wrote:
> As you suggested, the trailing slash is the culprit.
> This doesn't work:
>
> http://hostname/app
>
> But these all do:
>
> http://hostname/app/
> http://hostname/app/index
> http://hostname/app/index/
>
> Why does the last case work -- which also redirects with a 303 -- but
> not the first?

The trailing_slash tool, by default, performs an external redirect only
for missing slashes. So the last case, which has an extra slash,
redirects "index/" to "index" (which is then handled by root.app.index),
but it does so internally, without using HTTPRedirect.

The first case, which is missing a slash, may not be reaching CherryPy
at all depending on your deployment (e.g. mod_rewrite rules). How are
you mounting the app and with what args? quickstart(...)?
tree.mount(...)?

See the (new)
http://www.cherrypy.org/wiki/ErrorsAndExceptions#RedirectingPOST section
for more info on redirecting POST requests.


Robert Brewer
fuma...@aminus.org

Reply all
Reply to author
Forward
0 new messages