This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author demian.brecht
Recipients Arve.Knudsen, demian.brecht, eric.araujo, ezio.melotti, jcea, jimr, orsenthil, piotr.dobrogost, python-dev
Date 2015-02-26.16:41:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1424968879.04.0.759428044341.issue14721@psf.upfronthosting.co.za>
In-reply-to
Content
> I'm happy to produce a patch if there's any chance it would be merged.

If the patch adheres to the RFC, then I see no reason why it shouldn't be merged. What makes this a little more tricky than the snippet that you included in your post though (which would include the Content-Length header for all HTTP methods) is the following from RFC 7230:

   A user agent SHOULD send a Content-Length in a request message when
   no Transfer-Encoding is sent and the request method defines a meaning
   for an enclosed payload body.  For example, a Content-Length header
   field is normally sent in a POST request even when the value is 0
   (indicating an empty payload body).  A user agent SHOULD NOT send a
   Content-Length header field when the request message does not contain
   a payload body and the method semantics do not anticipate such a
   body.

Currently, there is nothing in the http package that defines whether or not a given HTTP method expects a body (as far as I'm aware at any rate), although this would be a simple addition. I'd imagine that the result might look like this:

_METHODS_EXPECTING_BODIES = {'OPTIONS', 'POST', 'PUT', 'PATCH'}

if method.upper() in _METHODS_EXPECTING_BODIES and \
        'content-length' not in header_names:
    self._set_content_length(body)

I'd prefer to have the conversion from None to empty string done in the body of _set_content_length in order to ensure consistency should the call be made from elsewhere.
History
Date User Action Args
2015-02-26 16:41:19demian.brechtsetrecipients: + demian.brecht, jcea, orsenthil, ezio.melotti, eric.araujo, Arve.Knudsen, python-dev, piotr.dobrogost, jimr
2015-02-26 16:41:19demian.brechtsetmessageid: <1424968879.04.0.759428044341.issue14721@psf.upfronthosting.co.za>
2015-02-26 16:41:19demian.brechtlinkissue14721 messages
2015-02-26 16:41:18demian.brechtcreate