mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
Fix Issue10012 - httplib headers, which are (sometimes mistakenly) int are explicitly cast to str (bytes - in py3k).
This commit is contained in:
parent
4271372a71
commit
58d5dbf80b
2 changed files with 11 additions and 0 deletions
|
@ -917,6 +917,8 @@ class HTTPConnection:
|
||||||
for i, one_value in enumerate(values):
|
for i, one_value in enumerate(values):
|
||||||
if hasattr(one_value, 'encode'):
|
if hasattr(one_value, 'encode'):
|
||||||
values[i] = one_value.encode('ascii')
|
values[i] = one_value.encode('ascii')
|
||||||
|
elif isinstance(one_value, int):
|
||||||
|
values[i] = str(one_value).encode('ascii')
|
||||||
value = b'\r\n\t'.join(values)
|
value = b'\r\n\t'.join(values)
|
||||||
header = header + b': ' + value
|
header = header + b': ' + value
|
||||||
self._output(header)
|
self._output(header)
|
||||||
|
|
|
@ -90,6 +90,15 @@ class HeaderTests(TestCase):
|
||||||
conn.request('POST', '/', body, headers)
|
conn.request('POST', '/', body, headers)
|
||||||
self.assertEqual(conn._buffer.count[header.lower()], 1)
|
self.assertEqual(conn._buffer.count[header.lower()], 1)
|
||||||
|
|
||||||
|
def test_putheader(self):
|
||||||
|
conn = client.HTTPConnection('example.com')
|
||||||
|
conn.sock = FakeSocket(None)
|
||||||
|
conn.putrequest('GET','/')
|
||||||
|
conn.putheader('Content-length', 42)
|
||||||
|
print(conn._buffer)
|
||||||
|
self.assertTrue(b'Content-length: 42' in conn._buffer)
|
||||||
|
|
||||||
|
|
||||||
class BasicTest(TestCase):
|
class BasicTest(TestCase):
|
||||||
def test_status_lines(self):
|
def test_status_lines(self):
|
||||||
# Test HTTP status lines
|
# Test HTTP status lines
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue