From: Senthil Kumaran Date: Sun, 3 Oct 2010 18:22:42 +0000 (+0000) Subject: Fix Issue10012 - httplib headers, which are (sometimes mistakenly) int are explicitly... X-Git-Tag: v3.2a3~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=58d5dbf80b8506e9f861c966125b023e591b682f;p=python Fix Issue10012 - httplib headers, which are (sometimes mistakenly) int are explicitly cast to str (bytes - in py3k). --- diff --git a/Lib/http/client.py b/Lib/http/client.py index 2799c070a0..34c098d961 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -917,6 +917,8 @@ class HTTPConnection: for i, one_value in enumerate(values): if hasattr(one_value, 'encode'): 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) header = header + b': ' + value self._output(header) diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index e9d24ba541..5a6422dcad 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -90,6 +90,15 @@ class HeaderTests(TestCase): conn.request('POST', '/', body, headers) 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): def test_status_lines(self): # Test HTTP status lines