We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
'Failed to parse headers' warning logged when getting message/rfc822 content
I've been investigating an [issue](https://github.com/boto/botocore/issues/1551) I've recently discovered when retrieving objects from S3. I've now tracked it to `urllib3`; this test case (which I've added to `urllib3/test/with_dummyserver/test_socketlevel.py`) demonstrates it:

```py
class TestOkayHeaders(SocketDummyServerTestCase):

    def _test_okay_header_parsing(self, header):
        self.start_response_handler((
           b'HTTP/1.1 200 OK\r\n'
           b'Content-Length: 0\r\n'
           ) + header + b'\r\n\r\n'
        )

        pool = HTTPConnectionPool(self.host, self.port, retries=False)
        self.addCleanup(pool.close)

        with LogRecorder() as logs:
            pool.request('GET', '/')

        for record in logs:
            assert 'Failed to parse headers' not in record.msg

    def test_header_text_plain(self):
        self._test_okay_header_parsing(b'Content-type: text/plain')

    def test_header_message_rfc822(self):
        self._test_okay_header_parsing(b'Content-type: message/rfc822')
```

The test with `text/plain` passes, while the test with `message/rfc822` fails, and this is logged:

```py
Failed to parse headers (url=http://localhost:36732/): Unknown, unparsed data: [<http.client.HTTPMessage object at 0x7f8fab9373c8>]
Traceback (most recent call last):
  File "/home/user/git/urllib3/src/urllib3/connectionpool.py", line 396, in _make_request
    assert_header_parsing(httplib_response.msg)
  File "/home/user/git/urllib3/src/urllib3/util/response.py", line 68, in assert_header_parsing
    raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)
urllib3.exceptions.HeaderParsingError: Unknown, unparsed data: [<http.client.HTTPMessage object at 0x7f8fab9373c8>]
```

While retrieving content of type `message/rfc822` still works, the warning message being logged is incorrect and unhelpful.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/urllib3/util/response.py`
Content:
```
1 from __future__ import absolute_import
2 from ..packages.six.moves import http_client as httplib
3 
4 from ..exceptions import HeaderParsingError
5 
6 
7 def is_fp_closed(obj):
8     """
9     Checks whether a given file-like object is closed.
10 
11     :param obj:
12         The file-like object to check.
13     """
14 
15     try:
16         # Check `isclosed()` first, in case Python3 doesn't set `closed`.
17         # GH Issue #928
18         return obj.isclosed()
19     except AttributeError:
20         pass
21 
22     try:
23         # Check via the official file-like-object way.
24         return obj.closed
25     except AttributeError:
26         pass
27 
28     try:
29         # Check if the object is a container for another file-like object that
30         # gets released on exhaustion (e.g. HTTPResponse).
31         return obj.fp is None
32     except AttributeError:
33         pass
34 
35     raise ValueError("Unable to determine whether fp is closed.")
36 
37 
38 def assert_header_parsing(headers):
39     """
40     Asserts whether all headers have been successfully parsed.
41     Extracts encountered errors from the result of parsing headers.
42 
43     Only works on Python 3.
44 
45     :param headers: Headers to verify.
46     :type headers: `httplib.HTTPMessage`.
47 
48     :raises urllib3.exceptions.HeaderParsingError:
49         If parsing errors are found.
50     """
51 
52     # This will fail silently if we pass in the wrong kind of parameter.
53     # To make debugging easier add an explicit check.
54     if not isinstance(headers, httplib.HTTPMessage):
55         raise TypeError('expected httplib.Message, got {0}.'.format(
56             type(headers)))
57 
58     defects = getattr(headers, 'defects', None)
59     get_payload = getattr(headers, 'get_payload', None)
60 
61     unparsed_data = None
62     if get_payload:  # Platform-specific: Python 3.
63         unparsed_data = get_payload()
64 
65     if defects or unparsed_data:
66         raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)
67 
68 
69 def is_response_to_head(response):
70     """
71     Checks whether the request of a response has been a HEAD-request.
72     Handles the quirks of AppEngine.
73 
74     :param conn:
75     :type conn: :class:`httplib.HTTPResponse`
76     """
77     # FIXME: Can we do this somehow without accessing private httplib _method?
78     method = response._method
79     if isinstance(method, int):  # Platform-specific: Appengine
80         return method == 3
81     return method.upper() == 'HEAD'
82
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/urllib3/util/response.py b/src/urllib3/util/response.py
--- a/src/urllib3/util/response.py
+++ b/src/urllib3/util/response.py
@@ -59,8 +59,14 @@
     get_payload = getattr(headers, 'get_payload', None)
 
     unparsed_data = None
-    if get_payload:  # Platform-specific: Python 3.
-        unparsed_data = get_payload()
+    if get_payload:
+        # get_payload is actually email.message.Message.get_payload;
+        # we're only interested in the result if it's not a multipart message
+        if not headers.is_multipart():
+            payload = get_payload()
+
+            if isinstance(payload, (bytes, str)):
+                unparsed_data = payload
 
     if defects or unparsed_data:
         raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)

{"golden_diff": "diff --git a/src/urllib3/util/response.py b/src/urllib3/util/response.py\n--- a/src/urllib3/util/response.py\n+++ b/src/urllib3/util/response.py\n@@ -59,8 +59,14 @@\n     get_payload = getattr(headers, 'get_payload', None)\n \n     unparsed_data = None\n-    if get_payload:  # Platform-specific: Python 3.\n-        unparsed_data = get_payload()\n+    if get_payload:\n+        # get_payload is actually email.message.Message.get_payload;\n+        # we're only interested in the result if it's not a multipart message\n+        if not headers.is_multipart():\n+            payload = get_payload()\n+\n+            if isinstance(payload, (bytes, str)):\n+                unparsed_data = payload\n \n     if defects or unparsed_data:\n         raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)\n", "issue": "'Failed to parse headers' warning logged when getting message/rfc822 content\nI've been investigating an [issue](https://github.com/boto/botocore/issues/1551) I've recently discovered when retrieving objects from S3. I've now tracked it to `urllib3`; this test case (which I've added to `urllib3/test/with_dummyserver/test_socketlevel.py`) demonstrates it:\r\n\r\n```py\r\nclass TestOkayHeaders(SocketDummyServerTestCase):\r\n\r\n    def _test_okay_header_parsing(self, header):\r\n        self.start_response_handler((\r\n           b'HTTP/1.1 200 OK\\r\\n'\r\n           b'Content-Length: 0\\r\\n'\r\n           ) + header + b'\\r\\n\\r\\n'\r\n        )\r\n\r\n        pool = HTTPConnectionPool(self.host, self.port, retries=False)\r\n        self.addCleanup(pool.close)\r\n\r\n        with LogRecorder() as logs:\r\n            pool.request('GET', '/')\r\n\r\n        for record in logs:\r\n            assert 'Failed to parse headers' not in record.msg\r\n\r\n    def test_header_text_plain(self):\r\n        self._test_okay_header_parsing(b'Content-type: text/plain')\r\n\r\n    def test_header_message_rfc822(self):\r\n        self._test_okay_header_parsing(b'Content-type: message/rfc822')\r\n```\r\n\r\nThe test with `text/plain` passes, while the test with `message/rfc822` fails, and this is logged:\r\n\r\n```py\r\nFailed to parse headers (url=http://localhost:36732/): Unknown, unparsed data: [<http.client.HTTPMessage object at 0x7f8fab9373c8>]\r\nTraceback (most recent call last):\r\n  File \"/home/user/git/urllib3/src/urllib3/connectionpool.py\", line 396, in _make_request\r\n    assert_header_parsing(httplib_response.msg)\r\n  File \"/home/user/git/urllib3/src/urllib3/util/response.py\", line 68, in assert_header_parsing\r\n    raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)\r\nurllib3.exceptions.HeaderParsingError: Unknown, unparsed data: [<http.client.HTTPMessage object at 0x7f8fab9373c8>]\r\n```\r\n\r\nWhile retrieving content of type `message/rfc822` still works, the warning message being logged is incorrect and unhelpful.\r\n\n", "before_files": [{"content": "from __future__ import absolute_import\nfrom ..packages.six.moves import http_client as httplib\n\nfrom ..exceptions import HeaderParsingError\n\n\ndef is_fp_closed(obj):\n    \"\"\"\n    Checks whether a given file-like object is closed.\n\n    :param obj:\n        The file-like object to check.\n    \"\"\"\n\n    try:\n        # Check `isclosed()` first, in case Python3 doesn't set `closed`.\n        # GH Issue #928\n        return obj.isclosed()\n    except AttributeError:\n        pass\n\n    try:\n        # Check via the official file-like-object way.\n        return obj.closed\n    except AttributeError:\n        pass\n\n    try:\n        # Check if the object is a container for another file-like object that\n        # gets released on exhaustion (e.g. HTTPResponse).\n        return obj.fp is None\n    except AttributeError:\n        pass\n\n    raise ValueError(\"Unable to determine whether fp is closed.\")\n\n\ndef assert_header_parsing(headers):\n    \"\"\"\n    Asserts whether all headers have been successfully parsed.\n    Extracts encountered errors from the result of parsing headers.\n\n    Only works on Python 3.\n\n    :param headers: Headers to verify.\n    :type headers: `httplib.HTTPMessage`.\n\n    :raises urllib3.exceptions.HeaderParsingError:\n        If parsing errors are found.\n    \"\"\"\n\n    # This will fail silently if we pass in the wrong kind of parameter.\n    # To make debugging easier add an explicit check.\n    if not isinstance(headers, httplib.HTTPMessage):\n        raise TypeError('expected httplib.Message, got {0}.'.format(\n            type(headers)))\n\n    defects = getattr(headers, 'defects', None)\n    get_payload = getattr(headers, 'get_payload', None)\n\n    unparsed_data = None\n    if get_payload:  # Platform-specific: Python 3.\n        unparsed_data = get_payload()\n\n    if defects or unparsed_data:\n        raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)\n\n\ndef is_response_to_head(response):\n    \"\"\"\n    Checks whether the request of a response has been a HEAD-request.\n    Handles the quirks of AppEngine.\n\n    :param conn:\n    :type conn: :class:`httplib.HTTPResponse`\n    \"\"\"\n    # FIXME: Can we do this somehow without accessing private httplib _method?\n    method = response._method\n    if isinstance(method, int):  # Platform-specific: Appengine\n        return method == 3\n    return method.upper() == 'HEAD'\n", "path": "src/urllib3/util/response.py"}], "after_files": [{"content": "from __future__ import absolute_import\nfrom ..packages.six.moves import http_client as httplib\n\nfrom ..exceptions import HeaderParsingError\n\n\ndef is_fp_closed(obj):\n    \"\"\"\n    Checks whether a given file-like object is closed.\n\n    :param obj:\n        The file-like object to check.\n    \"\"\"\n\n    try:\n        # Check `isclosed()` first, in case Python3 doesn't set `closed`.\n        # GH Issue #928\n        return obj.isclosed()\n    except AttributeError:\n        pass\n\n    try:\n        # Check via the official file-like-object way.\n        return obj.closed\n    except AttributeError:\n        pass\n\n    try:\n        # Check if the object is a container for another file-like object that\n        # gets released on exhaustion (e.g. HTTPResponse).\n        return obj.fp is None\n    except AttributeError:\n        pass\n\n    raise ValueError(\"Unable to determine whether fp is closed.\")\n\n\ndef assert_header_parsing(headers):\n    \"\"\"\n    Asserts whether all headers have been successfully parsed.\n    Extracts encountered errors from the result of parsing headers.\n\n    Only works on Python 3.\n\n    :param headers: Headers to verify.\n    :type headers: `httplib.HTTPMessage`.\n\n    :raises urllib3.exceptions.HeaderParsingError:\n        If parsing errors are found.\n    \"\"\"\n\n    # This will fail silently if we pass in the wrong kind of parameter.\n    # To make debugging easier add an explicit check.\n    if not isinstance(headers, httplib.HTTPMessage):\n        raise TypeError('expected httplib.Message, got {0}.'.format(\n            type(headers)))\n\n    defects = getattr(headers, 'defects', None)\n    get_payload = getattr(headers, 'get_payload', None)\n\n    unparsed_data = None\n    if get_payload:\n        # get_payload is actually email.message.Message.get_payload;\n        # we're only interested in the result if it's not a multipart message\n        if not headers.is_multipart():\n            payload = get_payload()\n\n            if isinstance(payload, (bytes, str)):\n                unparsed_data = payload\n\n    if defects or unparsed_data:\n        raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)\n\n\ndef is_response_to_head(response):\n    \"\"\"\n    Checks whether the request of a response has been a HEAD-request.\n    Handles the quirks of AppEngine.\n\n    :param conn:\n    :type conn: :class:`httplib.HTTPResponse`\n    \"\"\"\n    # FIXME: Can we do this somehow without accessing private httplib _method?\n    method = response._method\n    if isinstance(method, int):  # Platform-specific: Appengine\n        return method == 3\n    return method.upper() == 'HEAD'\n", "path": "src/urllib3/util/response.py"}]}