Issue #10980: encode headers with latin1 instead of ASCII in the HTTP server.
This makes the implementation of PEP 3333 compliant servers on top of BaseHTTPServer possible.
This commit is contained in:
parent
137e0f0a22
commit
8d96d77f9a
@ -448,7 +448,7 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
|
|||||||
message = ''
|
message = ''
|
||||||
if self.request_version != 'HTTP/0.9':
|
if self.request_version != 'HTTP/0.9':
|
||||||
self.wfile.write(("%s %d %s\r\n" %
|
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):
|
def send_header(self, keyword, value):
|
||||||
"""Send a MIME header."""
|
"""Send a MIME header."""
|
||||||
@ -456,7 +456,7 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
|
|||||||
if not hasattr(self, '_headers_buffer'):
|
if not hasattr(self, '_headers_buffer'):
|
||||||
self._headers_buffer = []
|
self._headers_buffer = []
|
||||||
self._headers_buffer.append(
|
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 keyword.lower() == 'connection':
|
||||||
if value.lower() == 'close':
|
if value.lower() == 'close':
|
||||||
|
@ -97,6 +97,11 @@ class BaseHTTPServerTestCase(BaseTestCase):
|
|||||||
self.send_header('Connection', 'close')
|
self.send_header('Connection', 'close')
|
||||||
self.end_headers()
|
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):
|
def setUp(self):
|
||||||
BaseTestCase.setUp(self)
|
BaseTestCase.setUp(self)
|
||||||
self.con = http.client.HTTPConnection('localhost', self.PORT)
|
self.con = http.client.HTTPConnection('localhost', self.PORT)
|
||||||
@ -194,6 +199,11 @@ class BaseHTTPServerTestCase(BaseTestCase):
|
|||||||
res = self.con.getresponse()
|
res = self.con.getresponse()
|
||||||
self.assertEqual(res.status, 999)
|
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 SimpleHTTPServerTestCase(BaseTestCase):
|
||||||
class request_handler(NoLogRequestHandler, SimpleHTTPRequestHandler):
|
class request_handler(NoLogRequestHandler, SimpleHTTPRequestHandler):
|
||||||
|
@ -29,6 +29,10 @@ Library
|
|||||||
- Issue #10898: Allow compiling the posix module when the C library defines
|
- Issue #10898: Allow compiling the posix module when the C library defines
|
||||||
a symbol named FSTAT.
|
a symbol named FSTAT.
|
||||||
|
|
||||||
|
- Issue #10980: the HTTP server now encodes headers with iso-8859-1 (latin1)
|
||||||
|
encoding. This is the preferred encoding of PEP 3333 and the base encoding
|
||||||
|
of HTTP 1.1.
|
||||||
|
|
||||||
|
|
||||||
What's New in Python 3.2 Release Candidate 1
|
What's New in Python 3.2 Release Candidate 1
|
||||||
============================================
|
============================================
|
||||||
|
Loading…
x
Reference in New Issue
Block a user