Google Groups Home
Help | Sign in
Request body of PUT with no Content-Type is processed incorrectly by CP3 (CP2 does it right)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Chris Miles  
View profile
 More options Feb 19, 6:01 am
From: Chris Miles <miles.ch...@gmail.com>
Date: Tue, 19 Feb 2008 03:01:59 -0800 (PST)
Local: Tues, Feb 19 2008 6:01 am
Subject: Request body of PUT with no Content-Type is processed incorrectly by CP3 (CP2 does it right)
I'm porting a CP2 app to CP3 (3.1.0beta3) and have an issue with CP3
Request.process_body() attempting to parse params from the request
body of a PUT request with no "Content-Type" header defined, which
wasn't how CP2 behaved in the same situation.

Given this super simple CP3 test app:
{{{
import cherrypy
class Root(object):
    @cherrypy.expose
    def upload(self):
        return "Upload OK"
cherrypy.quickstart(Root())

}}}

If I create a PUT request to /upload, with no "Content-Type" header
defined, then CP3 attempts to parse the request body (which, in my
case, contains binary data, but that doesn't matter) into params, and
the request fails because the params cannot be mapped to method
arguments (which you can examine by defining upload(self, *args,
**kwargs)) which is not what would be expected.  Compare this with the
same app running under CP2 and the request body is not parsed.

If I create a PUT request with any "Content-Type" (besides
"application/x-www-form-urlencoded" and similar) then the request
works properly (CP3 doesn't attempt to parse the request body).

If I create a PUT request with "Content-Type: application/x-www-form-
urlencoded" then CP3 does attempt to parse the request body (as I
would expect).

Here's some examples of the above behaviour using curl (error
responses truncated):
{{{
$ curl --upload-file ~/tmp/foo.tmp http://localhost:8080/upload
TypeError: upload() got an unexpected keyword argument 'test file.
# (works with CP2)

$ curl --header "Content-Type: foo/bar" --upload-file ~/tmp/foo.tmp
http://localhost:8080/upload
Upload OK

$ curl --header "Content-Type: application/x-www-form-urlencoded" --
upload-file ~/tmp/foo.tmp http://localhost:8080/upload
TypeError: upload() got an unexpected keyword argument 'test file.

}}}

I'd like to see the behaviour changed back to only attempting to parse
the request body if a valid form-like "Content-Type" (like
"application/x-www-form-urlencoded") is supplied, for a few reasons:

1. Request.body_params__doc (and Request.body__doc) indicate that this
is how it should behave, i.e. body_params: "If the request Content-
Type is 'application/x-www-form-urlencoded' or multipart, this will be
a dict of the params pulled from the entity body"; and body: "If the
request Content-Type is 'application/x-www-form-urlencoded' or
multipart, this will be None. Otherwise, this will contain the request
entity body as a string"

2. The request body should be left alone unless the Content-Type
indicates that it contains encoded parameters or multipart data.

3. This is how it worked in CP2.

In the case of my application, I don't want to force my users to
supply a Content-Type with their PUT request, when they didn't need to
before (doing so is optional).

If this is reasonable, I'm happy to create a ticket (and possibly a
patch) for CP3.

Cheers,
Chris Miles


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Brewer  
View profile
 More options Feb 19, 1:52 pm
From: "Robert Brewer" <fuman...@aminus.org>
Date: Tue, 19 Feb 2008 10:52:06 -0800
Local: Tues, Feb 19 2008 1:52 pm
Subject: RE: [cherrypy-devel] Request body of PUT with no Content-Type is processed incorrectly by CP3 (CP2 does it right)

Sounds good to me. RFC 2616 says:

   Any HTTP/1.1 message containing an entity-body SHOULD include a
   Content-Type header field defining the media type of that body. If
   and only if the media type is not given by a Content-Type field, the
   recipient MAY attempt to guess the media type via inspection of its
   content and/or the name extension(s) of the URI used to identify the
   resource. If the media type remains unknown, the recipient SHOULD
   treat it as type "application/octet-stream".

...which I read as: let the app decide since we don't want to get into
sniffing.

> If this is reasonable, I'm happy to create a ticket (and possibly a
> patch) for CP3.

Please do! :)

Robert Brewer
fuman...@aminus.org


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sylvain Hellegouarch  
View profile
 More options Feb 19, 2:54 pm
From: Sylvain Hellegouarch <s...@defuze.org>
Date: Tue, 19 Feb 2008 19:54:42 +0000
Local: Tues, Feb 19 2008 2:54 pm
Subject: Re: [cherrypy-devel] Re: Request body of PUT with no Content-Type is processed incorrectly by CP3 (CP2 does it right)

> Sounds good to me. RFC 2616 says:

>    Any HTTP/1.1 message containing an entity-body SHOULD include a
>    Content-Type header field defining the media type of that body. If
>    and only if the media type is not given by a Content-Type field, the
>    recipient MAY attempt to guess the media type via inspection of its
>    content and/or the name extension(s) of the URI used to identify the
>    resource. If the media type remains unknown, the recipient SHOULD
>    treat it as type "application/octet-stream".

> ...which I read as: let the app decide since we don't want to get into
> sniffing.

Indeed. However Chris, note that in the IETF language, a SHOULD is a
very strong requirement. They seldom use MUST but SHOULD means "we know
there are some cases where it won't be suitable but those should be rare
enough". I would invite you Chris to get the habit of sending the
content-type (you could actually hit some intermediairies that would get
you into trouble as well without that header).

- Sylvain


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Miles  
View profile
 More options Feb 20, 3:39 am
From: Chris Miles <miles.ch...@gmail.com>
Date: Wed, 20 Feb 2008 19:39:05 +1100
Local: Wed, Feb 20 2008 3:39 am
Subject: Re: [cherrypy-devel] Re: Request body of PUT with no Content-Type is processed incorrectly by CP3 (CP2 does it right)

On 20/02/2008, at 5:52 AM, Robert Brewer wrote:

Ticket created with patch attached.  http://www.cherrypy.org/ticket/790

Cheers,
Chris Miles


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Miles  
View profile
 More options Feb 20, 3:41 am
From: Chris Miles <miles.ch...@gmail.com>
Date: Wed, 20 Feb 2008 19:41:06 +1100
Local: Wed, Feb 20 2008 3:41 am
Subject: Re: [cherrypy-devel] Re: Request body of PUT with no Content-Type is processed incorrectly by CP3 (CP2 does it right)

On 20/02/2008, at 6:54 AM, Sylvain Hellegouarch wrote:

Good point Sylvain.  We actually encourage our clients to define a  
Content-Type, but we also make sure we handle cases where they leave  
it out.

Cheers,
Chris Miles


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google