]> granicus.if.org Git - python/commitdiff
Fix Issue10012 - httplib headers, which are (sometimes mistakenly) int are explicitly...
authorSenthil Kumaran <orsenthil@gmail.com>
Sun, 3 Oct 2010 18:22:42 +0000 (18:22 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Sun, 3 Oct 2010 18:22:42 +0000 (18:22 +0000)
Lib/http/client.py
Lib/test/test_httplib.py

index 2799c070a07d9615c38ad010f1f679c9fadc3ddf..34c098d961d93659e1296fc41ea5cb64d4477bac 100644 (file)
@@ -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)
index e9d24ba541c64f36b399c9a44cc6374753378fb7..5a6422dcad5df2480a2bf6650b5f60a444da2561 100644 (file)
@@ -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