diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2012-05-19 08:52:21 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2012-05-19 08:52:21 (GMT) |
commit | 618802d55e19c1f2da28c9409256a7f2fbf59e99 (patch) | |
tree | 8aa4d19a9e1f0c9a0b40e40e17bc19862daa18c0 /Lib/test/test_httplib.py | |
parent | ea24dda01f0bc151b55e922a1d5ec2b6193c8006 (diff) | |
download | cpython-618802d55e19c1f2da28c9409256a7f2fbf59e99.zip cpython-618802d55e19c1f2da28c9409256a7f2fbf59e99.tar.gz cpython-618802d55e19c1f2da28c9409256a7f2fbf59e99.tar.bz2 |
Fix Issue14721: Send Content-length: 0 for empty body () in the http.request
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r-- | Lib/test/test_httplib.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 05df875..5b5ae2e 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -90,6 +90,34 @@ class HeaderTests(TestCase): 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(':', 1) + if len(kv) > 1 and kv[0].lower() == 'content-length': + self.content_length = kv[1].strip() + list.append(self, item) + + # POST with empty body + conn = httplib.HTTPConnection('example.com') + conn.sock = FakeSocket(None) + conn._buffer = ContentLengthChecker() + conn.request('POST', '/', '') + self.assertEqual(conn._buffer.content_length, '0', + 'Header Content-Length not set') + + # PUT request with empty body + conn = httplib.HTTPConnection('example.com') + conn.sock = FakeSocket(None) + conn._buffer = ContentLengthChecker() + conn.request('PUT', '/', '') + self.assertEqual(conn._buffer.content_length, '0', + 'Header Content-Length not set') + def test_putheader(self): conn = httplib.HTTPConnection('example.com') conn.sock = FakeSocket(None) |