mirror of
https://github.com/python/cpython.git
synced 2025-08-24 02:35:59 +00:00
Fix Issue14721: Send Content-length: 0 for empty body () in the http.client requests
This commit is contained in:
parent
1be320ebdd
commit
5fa4a89601
3 changed files with 32 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue