]> granicus.if.org Git - python/commitdiff
Merged revisions 85205 via svnmerge from
authorSenthil Kumaran <orsenthil@gmail.com>
Sun, 3 Oct 2010 18:25:01 +0000 (18:25 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Sun, 3 Oct 2010 18:25:01 +0000 (18:25 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r85205 | senthil.kumaran | 2010-10-03 23:52:42 +0530 (Sun, 03 Oct 2010) | 3 lines

  Fix Issue10012 - httplib headers, which are (sometimes mistakenly) int are explicitly cast to str (bytes - in py3k).
........

Lib/http/client.py
Lib/test/test_httplib.py

index 9348870c3d97a6c474aaa4fe35d7c69f2e77decc..f273b03c6f61b41cb2162791d0818b6973a65ccb 100644 (file)
@@ -916,6 +916,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)
index 831d5aeb7cbc9ad33e1045505a39594288477ec1..642f06367da1dd54d27e3ddc24d996b078194fe5 100644 (file)
@@ -89,6 +89,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