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 demian.brecht
Date 2015-02-27.17:30:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1425058243.4.0.797359828619.issue23539@psf.upfronthosting.co.za>
In-reply-to
Content
#14721 solved setting the Content-Length header for 0-length bodies. However, it doesn't account for cases where body is None (reported by James Rutherford here: http://bugs.python.org/issue14721#msg236600).

One method of solving this might be something 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)

(_set_content_length would have to be updated in order to allow for None)

This ensures that Content-Length will not be set for methods not expecting a body.

RFC 7230, Section 3.3.2:

   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.
History
Date User Action Args
2015-02-27 17:30:43demian.brechtsetrecipients: + demian.brecht
2015-02-27 17:30:43demian.brechtsetmessageid: <1425058243.4.0.797359828619.issue23539@psf.upfronthosting.co.za>
2015-02-27 17:30:43demian.brechtlinkissue23539 messages
2015-02-27 17:30:43demian.brechtcreate