simple_client.py compliance to the RFC

8 views
Skip to first unread message

tiadobatima

unread,
Oct 5, 2012, 6:50:15 PM10/5/12
to python-...@googlegroups.com
Hello there,

We stumbled on this exception when sending POST/PUT requests without a body by mistake:

--- Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/tornado/iostream.py", line 304, in wrapper
callback(*args)
File "/usr/lib/python2.7/site-packages/tornado/simple_httpclient.py", line 276, in _on_connect
assert self.request.body is not None
AssertionError

---

The relevant code is here:


Even though it is not our intention to send body-less POST/PUT/PATCH, I can't find the RFC really prohibit them (unless I'm misinterpreting it)


Notice that this excerpt says that some methods must not include a body:
"A message-body MUST NOT be included in a request if the specification of the request method (section 5.1.1) does not allow sending an entity-body in requests"

But I can't find anything saying that some methods must include it.

I understand that body-less POST is not much different than a GET, but that's besides the point of the RFC compliance. These requests normally take different code paths within Tornado and other webservers anyways, and I suppose they should be valid.

What do you think?

Thanks guys! :)
g.

Ben Darnell

unread,
Oct 6, 2012, 12:23:51 AM10/6/12
to python-...@googlegroups.com
Yeah, I can't find anything that explicitly forbids POST or PUT
without a body (although at least for PUT the way it talks about "the
enclosed resource" only really makes sense if there is such a
resource. In any case, even if it's not technically required,
body-less POST and PUT is usually an error (likewise, GET with a body
is not prohibited, but is more likely to be a mistake than
intentional). This and other sanity checks are controlled by the
(poorly-named) allow_nonstandard_methods option. Pass
allow_nonstandard_methods=True in your request and simple_httpclient
will allow the request even it doesn't look quite right.

-Ben
Reply all
Reply to author
Forward
0 new messages