]> granicus.if.org Git - python/commitdiff
Merged revisions 85205 via svnmerge from
authorSenthil Kumaran <orsenthil@gmail.com>
Sun, 3 Oct 2010 18:26:07 +0000 (18:26 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Sun, 3 Oct 2010 18:26:07 +0000 (18:26 +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/httplib.py
Lib/test/test_httplib.py

index eb10ebad5d0508632b9311e449bfb6be91917813..526509c01ffaacd665873b8a0221df5b004b1d51 100644 (file)
@@ -915,7 +915,7 @@ class HTTPConnection:
         if self.__state != _CS_REQ_STARTED:
             raise CannotSendHeader()
 
-        hdr = '%s: %s' % (header, '\r\n\t'.join(values))
+        hdr = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values]))
         self._output(hdr)
 
     def endheaders(self, message_body=None):
index 435a9fc8b81b93340efb977fe195182554248b35..74301ff39accb8330ab617104b0ed05237c2cff5 100644 (file)
@@ -1,3 +1,4 @@
+import httplib
 import array
 import httplib
 import StringIO
@@ -64,8 +65,6 @@ class HeaderTests(TestCase):
         # Some headers are added automatically, but should not be added by
         # .request() if they are explicitly set.
 
-        import httplib
-
         class HeaderCountingBuffer(list):
             def __init__(self):
                 self.count = {}
@@ -91,6 +90,13 @@ class HeaderTests(TestCase):
                 conn.request('POST', '/', body, headers)
                 self.assertEqual(conn._buffer.count[header.lower()], 1)
 
+    def test_putheader(self):
+        conn = httplib.HTTPConnection('example.com')
+        conn.sock = FakeSocket(None)
+        conn.putrequest('GET','/')
+        conn.putheader('Content-length',42)
+        self.assertTrue('Content-length: 42' in conn._buffer)
+
 class BasicTest(TestCase):
     def test_status_lines(self):
         # Test HTTP status lines