Commit 5b910d21 authored by Jeremy Hylton's avatar Jeremy Hylton

Fix compatibility issue with HTTPMessage class.

The server needs to use MessageClass to parse.
parent 523d996c
...@@ -213,7 +213,6 @@ class HTTPMessage(email.message.Message): ...@@ -213,7 +213,6 @@ class HTTPMessage(email.message.Message):
occurrences are returned. Case is not important in the header name. occurrences are returned. Case is not important in the header name.
""" """
# XXX: copied from rfc822.Message for compatibility
name = name.lower() + ':' name = name.lower() + ':'
n = len(name) n = len(name)
lst = [] lst = []
...@@ -227,7 +226,7 @@ class HTTPMessage(email.message.Message): ...@@ -227,7 +226,7 @@ class HTTPMessage(email.message.Message):
lst.append(line) lst.append(line)
return lst return lst
def parse_headers(fp): def parse_headers(fp, _class=HTTPMessage):
"""Parses only RFC2822 headers from a file pointer. """Parses only RFC2822 headers from a file pointer.
email Parser wants to see strings rather than bytes. email Parser wants to see strings rather than bytes.
...@@ -245,7 +244,7 @@ def parse_headers(fp): ...@@ -245,7 +244,7 @@ def parse_headers(fp):
break break
hstring = b''.join(headers).decode('iso-8859-1') hstring = b''.join(headers).decode('iso-8859-1')
return email.parser.Parser(_class=HTTPMessage).parsestr(hstring) return email.parser.Parser(_class=_class).parsestr(hstring)
class HTTPResponse(io.RawIOBase): class HTTPResponse(io.RawIOBase):
......
...@@ -313,7 +313,8 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler): ...@@ -313,7 +313,8 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
self.command, self.path, self.request_version = command, path, version self.command, self.path, self.request_version = command, path, version
# Examine the headers and look for a Connection directive. # Examine the headers and look for a Connection directive.
self.headers = http.client.parse_headers(self.rfile) self.headers = http.client.parse_headers(self.rfile,
_class=self.MessageClass)
conntype = self.headers.get('Connection', "") conntype = self.headers.get('Connection', "")
if conntype.lower() == 'close': if conntype.lower() == 'close':
......
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