Index: Doc/library/xmlrpclib.rst
===================================================================
--- Doc/library/xmlrpclib.rst	(revision 57274)
+++ Doc/library/xmlrpclib.rst	(working copy)
@@ -305,7 +305,7 @@
 
 .. attribute:: ProtocolError.headers
 
-   A string containing the headers of the HTTP/HTTPS request that triggered the
+   A dict containing the headers of the HTTP/HTTPS request that triggered the
    error.
 
 
Index: Lib/xmlrpclib.py
===================================================================
--- Lib/xmlrpclib.py	(revision 57274)
+++ Lib/xmlrpclib.py	(working copy)
@@ -1118,7 +1118,7 @@
             raise ProtocolError(
                 host + handler,
                 resp.status, resp.reason,
-                resp.getheaders()
+                dict(resp.getheaders())
                 )
 
         self.verbose = verbose
Index: Lib/BaseHTTPServer.py
===================================================================
--- Lib/BaseHTTPServer.py	(revision 57274)
+++ Lib/BaseHTTPServer.py	(working copy)
@@ -278,15 +278,22 @@
             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))
+        self.headers = self.MessageClass(hfile)
+
         conntype = self.headers.get('Connection', "")
         if conntype.lower() == 'close':
             self.close_connection = 1
Index: Lib/test/test_xmlrpc.py
===================================================================
--- Lib/test/test_xmlrpc.py	(revision 57274)
+++ Lib/test/test_xmlrpc.py	(working copy)
@@ -1,5 +1,6 @@
 import base64
 import datetime
+import re
 import sys
 import time
 import unittest
@@ -406,8 +407,9 @@
             p.pow(6,8)
         except xmlrpclib.ProtocolError as e:
             # We should get error info in the response
-            expected_err = "invalid literal for int() with base 10: 'I am broken'"
-            self.assertEqual(e.headers.get("x-exception"), expected_err)
+            expected_err = re.compile(
+                r"invalid literal for int\(\) with base 10: s?'I am broken'$")
+            self.assertTrue(expected_err.match(e.headers.get("x-exception")))
             self.assertTrue(e.headers.get("x-traceback") is not None)
         else:
             self.fail('ProtocolError not raised')
