changeset: 77049:732d70746fc0 parent: 77046:152c78b94e41 parent: 77048:6da1ab5f777d user: Senthil Kumaran date: Sat May 19 16:58:45 2012 +0800 files: Lib/http/client.py Lib/test/test_httplib.py Misc/NEWS description: merge - Fix Issue14721: Send Content-length: 0 for empty body () in the http.client requests diff -r 152c78b94e41 -r 732d70746fc0 Lib/http/client.py --- a/Lib/http/client.py Sat May 19 08:12:46 2012 +0800 +++ b/Lib/http/client.py Sat May 19 16:58:45 2012 +0800 @@ -1076,7 +1076,7 @@ self.putrequest(method, url, **skips) - if body and ('content-length' not in header_names): + if body is not None and ('content-length' not in header_names): self._set_content_length(body) for hdr, value in headers.items(): self.putheader(hdr, value) diff -r 152c78b94e41 -r 732d70746fc0 Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py Sat May 19 08:12:46 2012 +0800 +++ b/Lib/test/test_httplib.py Sat May 19 16:58:45 2012 +0800 @@ -99,6 +99,34 @@ conn.request('POST', '/', body, headers) self.assertEqual(conn._buffer.count[header.lower()], 1) + def test_content_length_0(self): + + class ContentLengthChecker(list): + def __init__(self): + list.__init__(self) + self.content_length = None + def append(self, item): + kv = item.split(b':', 1) + if len(kv)> 1 and kv[0].lower() == b'content-length': + self.content_length = kv[1].strip() + list.append(self, item) + + # POST with empty body + conn = client.HTTPConnection('example.com') + conn.sock = FakeSocket(None) + conn._buffer = ContentLengthChecker() + conn.request('POST', '/', '') + self.assertEqual(conn._buffer.content_length, b'0', + 'Header Content-Length not set') + + # PUT request with empty body + conn = client.HTTPConnection('example.com') + conn.sock = FakeSocket(None) + conn._buffer = ContentLengthChecker() + conn.request('PUT', '/', '') + self.assertEqual(conn._buffer.content_length, b'0', + 'Header Content-Length not set') + def test_putheader(self): conn = client.HTTPConnection('example.com') conn.sock = FakeSocket(None) diff -r 152c78b94e41 -r 732d70746fc0 Misc/NEWS --- a/Misc/NEWS Sat May 19 08:12:46 2012 +0800 +++ b/Misc/NEWS Sat May 19 16:58:45 2012 +0800 @@ -38,6 +38,9 @@ Library ------- +- Issue #14721: Send the correct 'Content-length: 0' header when the body is an + empty string ''. Initial Patch contributed by Arve Knudsen. + - Issue #9374: Generic parsing of query and fragment portions of url for any scheme. Supported both by RFC3986 and RFC2396.

AltStyle によって変換されたページ (->オリジナル) /