prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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.
  
  
  </issue>
  <code>
  [start of src/urllib3/util/response.py]
  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 of src/urllib3/util/response.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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)
  
verification_info: {"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"}]}