Commit 5bf1a645 authored by Armin Ronacher's avatar Armin Ronacher

To match the behaviour of HTTP server, the HTTP client library now also encodes

headers with iso-8859-1 (latin1) encoding.  It was already doing that for
incoming headers which makes this behaviour now consistent in both incoming and
outgoing direction.
parent 1aa960f2
...@@ -696,7 +696,7 @@ class HTTPConnection: ...@@ -696,7 +696,7 @@ class HTTPConnection:
self.send(connect_bytes) self.send(connect_bytes)
for header, value in self._tunnel_headers.iteritems(): for header, value in self._tunnel_headers.iteritems():
header_str = "%s: %s\r\n" % (header, value) header_str = "%s: %s\r\n" % (header, value)
header_bytes = header_str.encode("ascii") header_bytes = header_str.encode("latin1")
self.send(header_bytes) self.send(header_bytes)
response = self.response_class(self.sock, method = self._method) response = self.response_class(self.sock, method = self._method)
...@@ -935,7 +935,7 @@ class HTTPConnection: ...@@ -935,7 +935,7 @@ class HTTPConnection:
values = list(values) values = list(values)
for i, one_value in enumerate(values): for i, one_value in enumerate(values):
if hasattr(one_value, 'encode'): if hasattr(one_value, 'encode'):
values[i] = one_value.encode('ascii') values[i] = one_value.encode('latin1')
elif isinstance(one_value, int): elif isinstance(one_value, int):
values[i] = str(one_value).encode('ascii') values[i] = str(one_value).encode('ascii')
value = b'\r\n\t'.join(values) value = b'\r\n\t'.join(values)
......
...@@ -100,7 +100,10 @@ class BaseHTTPServerTestCase(BaseTestCase): ...@@ -100,7 +100,10 @@ class BaseHTTPServerTestCase(BaseTestCase):
def do_LATINONEHEADER(self): def do_LATINONEHEADER(self):
self.send_response(999) self.send_response(999)
self.send_header('X-Special', 'Dängerous Mind') self.send_header('X-Special', 'Dängerous Mind')
self.send_header('Connection', 'close')
self.end_headers() self.end_headers()
body = self.headers['x-special-incoming'].encode('utf-8')
self.wfile.write(body)
def setUp(self): def setUp(self):
BaseTestCase.setUp(self) BaseTestCase.setUp(self)
...@@ -200,9 +203,12 @@ class BaseHTTPServerTestCase(BaseTestCase): ...@@ -200,9 +203,12 @@ class BaseHTTPServerTestCase(BaseTestCase):
self.assertEqual(res.status, 999) self.assertEqual(res.status, 999)
def test_latin1_header(self): def test_latin1_header(self):
self.con.request('LATINONEHEADER', '/') self.con.request('LATINONEHEADER', '/', headers={
'X-Special-Incoming': 'Ärger mit Unicode'
})
res = self.con.getresponse() res = self.con.getresponse()
self.assertEqual(res.getheader('X-Special'), 'Dängerous Mind') self.assertEqual(res.getheader('X-Special'), 'Dängerous Mind')
self.assertEqual(res.read(), 'Ärger mit Unicode'.encode('utf-8'))
class SimpleHTTPServerTestCase(BaseTestCase): class SimpleHTTPServerTestCase(BaseTestCase):
......
...@@ -33,6 +33,11 @@ Library ...@@ -33,6 +33,11 @@ Library
encoding. This is the preferred encoding of PEP 3333 and the base encoding encoding. This is the preferred encoding of PEP 3333 and the base encoding
of HTTP 1.1. of HTTP 1.1.
- To match the behaviour of HTTP server, the HTTP client library now also
encodes headers with iso-8859-1 (latin1) encoding. It was already doing
that for incoming headers which makes this behaviour now consistent in
both incoming and outgoing direction.
What's New in Python 3.2 Release Candidate 1 What's New in Python 3.2 Release Candidate 1
============================================ ============================================
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment