Demian Brecht added the comment:

> My feeling is that '' implies "present but empty" (so should have a 
> content-length set to zero), whereas None implies "missing" (so should only 
> have a content-length header set to zero if the method is expecting a body.

Although I understand your thinking here, I think that bodies that are either 
None or empty string should be treated identically. Whether or not the 
Content-Length header is set should be dependent on the method used.

>From a client standpoint, there’s no difference between sending a body with a 
>value of None and an empty string (the latter will get further down the call 
>stack, but no data is actually sent over the wire).

Likewise from the server standpoint, there is no functional difference between 
a missing or empty body. However, there’s still the possibility of unexpected 
behaviour due to the inclusion of a Content-Length header for a method not 
expecting it.

In light of that, I think that HTTPConnection(‘example.com’).request(‘GET’, 
‘/‘, ‘’) and HTTPConnection(‘example.com’).request(‘GET’, ‘/‘) should result in 
identical headers with no Content-Length set.

If someone /really/ wants to set the Content-Length header for a method that 
doesn’t expect it, they still have the ability to do so: 
HTTPConnection(‘example.com’).request(‘GET’, ‘/‘, ‘’, {‘Content-Length’: 0}). 
However, if the default behaviour is to include the Content-Length header for 
an empty string, the user then has to change what they’re sending to be None 
instead of empty string even though they should be functionally equivalent.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23539>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to