Skip to content

Commit

Permalink
Fix Issue10012 - httplib headers, which are (sometimes mistakenly) in…
Browse files Browse the repository at this point in the history
…t are explicitly cast to str (bytes - in py3k).
  • Loading branch information
orsenthil committed Oct 3, 2010
1 parent 4271372 commit 58d5dbf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,8 @@ def putheader(self, header, *values):
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)
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ def append(self, item):
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
Expand Down

0 comments on commit 58d5dbf

Please sign in to comment.