diff options
| author | Senthil Kumaran <senthil@uthcode.com> | 2012-05-19 08:58:45 (GMT) | 
|---|---|---|
| committer | Senthil Kumaran <senthil@uthcode.com> | 2012-05-19 08:58:45 (GMT) | 
| commit | d34b57a9a2810e79d6f6aa7dc12832c4e4b214a5 (patch) | |
| tree | a16209eba6109a3dac0779b159cd09feef54c3b9 /Lib/test | |
| parent | 15e848b0767c41e6badc45316d60aa588d7e5ac1 (diff) | |
| parent | 5fa4a896016e8a265b6afee64c61a1083c6ffa47 (diff) | |
| download | cpython-d34b57a9a2810e79d6f6aa7dc12832c4e4b214a5.zip cpython-d34b57a9a2810e79d6f6aa7dc12832c4e4b214a5.tar.gz cpython-d34b57a9a2810e79d6f6aa7dc12832c4e4b214a5.tar.bz2  | |
merge - Fix Issue14721: Send Content-length: 0 for empty body () in the http.client requests
Diffstat (limited to 'Lib/test')
| -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 cc6cd07..cf61552 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -99,6 +99,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(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)  | 
