Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cfe02a4

Browse files
committed
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.
1 parent 2523621 commit cfe02a4

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

Lib/BaseHTTPServer.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,21 @@ def parse_request(self):
278278
return False
279279
self.command, self.path, self.request_version = command, path, version
280280

281-
# Examine the headers and look for a Connection directive
282-
# MessageClass == rfc822 expects ascii, so use a text wrapper.
283-
text = io.TextIOWrapper(self.rfile)
284-
self.headers = self.MessageClass(text, 0)
285-
# The text wrapper does buffering (as does self.rfile). We
286-
# don't want to leave any data in the buffer of the text
287-
# wrapper.
288-
assert not text.buffer.peek()
281+
# Examine the headers and look for a Connection directive.
282+
283+
# MessageClass (rfc822) wants to see strings rather than bytes.
284+
# But a TextIOWrapper around self.rfile would buffer too many bytes
285+
# from the stream, bytes which we later need to read as bytes.
286+
# So we read the correct bytes here, as bytes, then use StringIO
287+
# to make them look like strings for MessageClass to parse.
288+
headers = []
289+
while True:
290+
line = self.rfile.readline()
291+
headers.append(line)
292+
if line in (b'\r\n', b'\n', b''):
293+
break
294+
hfile = io.StringIO(b''.join(headers).decode('iso-8859-1'))
295+
self.headers = self.MessageClass(hfile)
289296

290297
conntype = self.headers.get('Connection', "")
291298
if conntype.lower() == 'close':

Lib/xmlrpclib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ def request(self, host, handler, request_body, verbose=0):
11181118
raise ProtocolError(
11191119
host + handler,
11201120
resp.status, resp.reason,
1121-
resp.getheaders()
1121+
dict(resp.getheaders())
11221122
)
11231123

11241124
self.verbose = verbose

0 commit comments

Comments
 (0)