summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-22 23:45:42 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-22 23:45:42 (GMT)
commitcfe02a498b107a6436003e2bf7a48aefe4e3d59f (patch)
treeeac6d7f4402753f357921978ef2b2d3aed82c3a0 /Lib
parent2523621693102663ff449237ef07810d9e6fa919 (diff)
downloadcpython-cfe02a498b107a6436003e2bf7a48aefe4e3d59f.zip
cpython-cfe02a498b107a6436003e2bf7a48aefe4e3d59f.tar.gz
cpython-cfe02a498b107a6436003e2bf7a48aefe4e3d59f.tar.bz2
Fixes by John Reese and Jacques Frechet that make test_xmlrpc pass.
(Note that test_xmlrpc isn't touched by the fixes!) There were two separate issues; (a) BaseHTTPServer was using a TextIOWrapper which was swallowing some of the POST body; (b) the getheaders() API was changed but (due to integration of 2.6 code) the code wasn't modified.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/BaseHTTPServer.py23
-rw-r--r--Lib/xmlrpclib.py2
2 files changed, 16 insertions, 9 deletions
diff --git a/Lib/BaseHTTPServer.py b/Lib/BaseHTTPServer.py
index 1ba0ac7..56e2169 100644
--- a/Lib/BaseHTTPServer.py
+++ b/Lib/BaseHTTPServer.py
@@ -278,14 +278,21 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
return False
self.command, self.path, self.request_version = command, path, version
- # Examine the headers and look for a Connection directive
- # MessageClass == rfc822 expects ascii, so use a text wrapper.
- text = io.TextIOWrapper(self.rfile)
- self.headers = self.MessageClass(text, 0)
- # The text wrapper does buffering (as does self.rfile). We
- # don't want to leave any data in the buffer of the text
- # wrapper.
- assert not text.buffer.peek()
+ # Examine the headers and look for a Connection directive.
+
+ # MessageClass (rfc822) wants to see strings rather than bytes.
+ # But a TextIOWrapper around self.rfile would buffer too many bytes
+ # from the stream, bytes which we later need to read as bytes.
+ # So we read the correct bytes here, as bytes, then use StringIO
+ # to make them look like strings for MessageClass to parse.
+ headers = []
+ while True:
+ line = self.rfile.readline()
+ headers.append(line)
+ if line in (b'\r\n', b'\n', b''):
+ break
+ hfile = io.StringIO(b''.join(headers).decode('iso-8859-1'))
+ self.headers = self.MessageClass(hfile)
conntype = self.headers.get('Connection', "")
if conntype.lower() == 'close':
diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py
index 2da17c4..abd1a07 100644
--- a/Lib/xmlrpclib.py
+++ b/Lib/xmlrpclib.py
@@ -1118,7 +1118,7 @@ class Transport:
raise ProtocolError(
host + handler,
resp.status, resp.reason,
- resp.getheaders()
+ dict(resp.getheaders())
)
self.verbose = verbose