Commit 811fc149 authored by Jeremy Hylton's avatar Jeremy Hylton

Fix status line parsing for http response.

parent 4737482f
...@@ -264,7 +264,7 @@ class HTTPMessage(mimetools.Message): ...@@ -264,7 +264,7 @@ class HTTPMessage(mimetools.Message):
except IOError: except IOError:
startofline = tell = None startofline = tell = None
self.seekable = 0 self.seekable = 0
line = self.fp.readline() line = str(self.fp.readline(), "iso-8859-1")
if not line: if not line:
self.status = 'EOF in headers' self.status = 'EOF in headers'
break break
...@@ -317,6 +317,11 @@ class HTTPResponse: ...@@ -317,6 +317,11 @@ class HTTPResponse:
# See RFC 2616 sec 19.6 and RFC 1945 sec 6 for details. # See RFC 2616 sec 19.6 and RFC 1945 sec 6 for details.
# The bytes from the socket object are iso-8859-1 strings.
# See RFC 2616 sec 2.2 which notes an exception for MIME-encoded
# text following RFC 2047. The basic status line parsing only
# accepts iso-8859-1.
def __init__(self, sock, debuglevel=0, strict=0, method=None): def __init__(self, sock, debuglevel=0, strict=0, method=None):
self.fp = sock.makefile('rb', 0) self.fp = sock.makefile('rb', 0)
self.debuglevel = debuglevel self.debuglevel = debuglevel
...@@ -337,7 +342,7 @@ class HTTPResponse: ...@@ -337,7 +342,7 @@ class HTTPResponse:
def _read_status(self): def _read_status(self):
# Initialize with Simple-Response defaults # Initialize with Simple-Response defaults
line = self.fp.readline() line = str(self.fp.readline(), "iso-8859-1")
if self.debuglevel > 0: if self.debuglevel > 0:
print("reply:", repr(line)) print("reply:", repr(line))
if not line: if not line:
......
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