Index: Lib/http/server.py =================================================================== --- Lib/http/server.py (revision 88141) +++ Lib/http/server.py (working copy) @@ -448,7 +448,7 @@ message = '' if self.request_version != 'HTTP/0.9': self.wfile.write(("%s %d %s\r\n" % - (self.protocol_version, code, message)).encode('ASCII', 'strict')) + (self.protocol_version, code, message)).encode('latin1', 'strict')) def send_header(self, keyword, value): """Send a MIME header.""" @@ -456,7 +456,7 @@ if not hasattr(self, '_headers_buffer'): self._headers_buffer = [] self._headers_buffer.append( - ("%s: %s\r\n" % (keyword, value)).encode('ASCII', 'strict')) + ("%s: %s\r\n" % (keyword, value)).encode('latin1', 'strict')) if keyword.lower() == 'connection': if value.lower() == 'close': Index: Lib/test/test_httpservers.py =================================================================== --- Lib/test/test_httpservers.py (revision 88141) +++ Lib/test/test_httpservers.py (working copy) @@ -97,6 +97,11 @@ self.send_header('Connection', 'close') self.end_headers() + def do_LATINONEHEADER(self): + self.send_response(999) + self.send_header('X-Special', 'Dängerous Mind') + self.end_headers() + def setUp(self): BaseTestCase.setUp(self) self.con = http.client.HTTPConnection('localhost', self.PORT) @@ -194,7 +199,12 @@ res = self.con.getresponse() self.assertEqual(res.status, 999) + def test_latin1_header(self): + self.con.request('LATINONEHEADER', '/') + res = self.con.getresponse() + self.assertEqual(res.getheader('X-Special'), 'Dängerous Mind') + class SimpleHTTPServerTestCase(BaseTestCase): class request_handler(NoLogRequestHandler, SimpleHTTPRequestHandler): pass