prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Multipart mixed responses generate warnings
  If you read a multipart/mixed response, the connectionpool issues a couple of warnings about defects in the message. I'm not sure what the expected, correct behavior is, but these warnings seem spurious.
  
  Stick this perl script somewhere:
  
  ```
  #!/usr/bin/perl
  
  print "Server: Some Server Name\r\n";
  print "Content-Type: multipart/mixed; boundary=36eeb8c4e26d842a\r\n";
  print "Content-Length: 178\r\n";
  print "\r\n\r\n";
  print "--36eeb8c4e26d842a\r\n";
  print "Content-Type: text/plain\r\n";
  print "\r\n";
  print "7\r\n";
  print "--36eeb8c4e26d842a\r\n";
  print "Content-Type: text/plain\r\n";
  print "\r\n";
  print "9\r\n";
  print "--36eeb8c4e26d842a\r\n";
  print "Content-Type: text/plain\r\n";
  print "\r\n";
  print "11\r\n";
  print "--36eeb8c4e26d842a--\r\n";
  ```
  
  Read it with requests (naturally, you'll have to change the URI to wherever you put the script):
  
  ```
  import requests, logging
  
  logging.basicConfig(level=logging.WARNING)
  logging.getLogger("requests").setLevel(logging.DEBUG)
  
  headers = {'accept': "multipart/mixed"}
  r = requests.get("http://localhost:8124/cgi-bin/mpm.pl", headers=headers)
  
  print(r)
  ```
  
  The following errors are displayed:
  
  ```
  DEBUG:requests.packages.urllib3.connectionpool:"GET http://localhost:8124/cgi-bin/mpm.pl HTTP/1.1" 200 178
  WARNING:requests.packages.urllib3.connectionpool:Failed to parse headers (url=http://localhost:8888/http://localhost:8124/cgi-bin/mpm.pl): [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ''
  Traceback (most recent call last):
    File "/home/ndw/.virtualenvs/pyapi/lib/python3.4/site-packages/requests-2.8.0-py3.4.egg/requests/packages/urllib3/connectionpool.py", line 390, in _make_request
      assert_header_parsing(httplib_response.msg)
    File "/home/ndw/.virtualenvs/pyapi/lib/python3.4/site-packages/requests-2.8.0-py3.4.egg/requests/packages/urllib3/util/response.py", line 58, in assert_header_parsing
      raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)
  requests.packages.urllib3.exceptions.HeaderParsingError: [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ''
  ```
  
  It took me quite a while to work out that they were spurious (because in real life, the server side that is generating the multipart/mixed is more complicated!)
  
  See also kennethreitz/requests#3001
  ## 
  
  
  </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(type(headers)))
  56 
  57     defects = getattr(headers, "defects", None)
  58     get_payload = getattr(headers, "get_payload", None)
  59 
  60     unparsed_data = None
  61     if get_payload:
  62         # get_payload is actually email.message.Message.get_payload;
  63         # we're only interested in the result if it's not a multipart message
  64         if not headers.is_multipart():
  65             payload = get_payload()
  66 
  67             if isinstance(payload, (bytes, str)):
  68                 unparsed_data = payload
  69 
  70     if defects or unparsed_data:
  71         raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)
  72 
  73 
  74 def is_response_to_head(response):
  75     """
  76     Checks whether the request of a response has been a HEAD-request.
  77     Handles the quirks of AppEngine.
  78 
  79     :param conn:
  80     :type conn: :class:`httplib.HTTPResponse`
  81     """
  82     # FIXME: Can we do this somehow without accessing private httplib _method?
  83     method = response._method
  84     if isinstance(method, int):  # Platform-specific: Appengine
  85         return method == 3
  86     return method.upper() == "HEAD"
  87
  [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
  @@ -1,4 +1,5 @@
   from __future__ import absolute_import
  +from email.errors import StartBoundaryNotFoundDefect, MultipartInvariantViolationDefect
   from ..packages.six.moves import http_client as httplib
   
   from ..exceptions import HeaderParsingError
  @@ -66,6 +67,25 @@
   
               if isinstance(payload, (bytes, str)):
                   unparsed_data = payload
  +    if defects:
  +        # httplib is assuming a response body is available
  +        # when parsing headers even when httplib only sends
  +        # header data to parse_headers() This results in
  +        # defects on multipart responses in particular.
  +        # See: https://github.com/urllib3/urllib3/issues/800
  +
  +        # So we ignore the following defects:
  +        # - StartBoundaryNotFoundDefect:
  +        #     The claimed start boundary was never found.
  +        # - MultipartInvariantViolationDefect:
  +        #     A message claimed to be a multipart but no subparts were found.
  +        defects = [
  +            defect
  +            for defect in defects
  +            if not isinstance(
  +                defect, (StartBoundaryNotFoundDefect, MultipartInvariantViolationDefect)
  +            )
  +        ]
   
       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@@ -1,4 +1,5 @@\n from __future__ import absolute_import\n+from email.errors import StartBoundaryNotFoundDefect, MultipartInvariantViolationDefect\n from ..packages.six.moves import http_client as httplib\n \n from ..exceptions import HeaderParsingError\n@@ -66,6 +67,25 @@\n \n             if isinstance(payload, (bytes, str)):\n                 unparsed_data = payload\n+    if defects:\n+        # httplib is assuming a response body is available\n+        # when parsing headers even when httplib only sends\n+        # header data to parse_headers() This results in\n+        # defects on multipart responses in particular.\n+        # See: https://github.com/urllib3/urllib3/issues/800\n+\n+        # So we ignore the following defects:\n+        # - StartBoundaryNotFoundDefect:\n+        #     The claimed start boundary was never found.\n+        # - MultipartInvariantViolationDefect:\n+        #     A message claimed to be a multipart but no subparts were found.\n+        defects = [\n+            defect\n+            for defect in defects\n+            if not isinstance(\n+                defect, (StartBoundaryNotFoundDefect, MultipartInvariantViolationDefect)\n+            )\n+        ]\n \n     if defects or unparsed_data:\n         raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)\n", "issue": "Multipart mixed responses generate warnings\nIf you read a multipart/mixed response, the connectionpool issues a couple of warnings about defects in the message. I'm not sure what the expected, correct behavior is, but these warnings seem spurious.\n\nStick this perl script somewhere:\n\n```\n#!/usr/bin/perl\n\nprint \"Server: Some Server Name\\r\\n\";\nprint \"Content-Type: multipart/mixed; boundary=36eeb8c4e26d842a\\r\\n\";\nprint \"Content-Length: 178\\r\\n\";\nprint \"\\r\\n\\r\\n\";\nprint \"--36eeb8c4e26d842a\\r\\n\";\nprint \"Content-Type: text/plain\\r\\n\";\nprint \"\\r\\n\";\nprint \"7\\r\\n\";\nprint \"--36eeb8c4e26d842a\\r\\n\";\nprint \"Content-Type: text/plain\\r\\n\";\nprint \"\\r\\n\";\nprint \"9\\r\\n\";\nprint \"--36eeb8c4e26d842a\\r\\n\";\nprint \"Content-Type: text/plain\\r\\n\";\nprint \"\\r\\n\";\nprint \"11\\r\\n\";\nprint \"--36eeb8c4e26d842a--\\r\\n\";\n```\n\nRead it with requests (naturally, you'll have to change the URI to wherever you put the script):\n\n```\nimport requests, logging\n\nlogging.basicConfig(level=logging.WARNING)\nlogging.getLogger(\"requests\").setLevel(logging.DEBUG)\n\nheaders = {'accept': \"multipart/mixed\"}\nr = requests.get(\"http://localhost:8124/cgi-bin/mpm.pl\", headers=headers)\n\nprint(r)\n```\n\nThe following errors are displayed:\n\n```\nDEBUG:requests.packages.urllib3.connectionpool:\"GET http://localhost:8124/cgi-bin/mpm.pl HTTP/1.1\" 200 178\nWARNING:requests.packages.urllib3.connectionpool:Failed to parse headers (url=http://localhost:8888/http://localhost:8124/cgi-bin/mpm.pl): [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ''\nTraceback (most recent call last):\n  File \"/home/ndw/.virtualenvs/pyapi/lib/python3.4/site-packages/requests-2.8.0-py3.4.egg/requests/packages/urllib3/connectionpool.py\", line 390, in _make_request\n    assert_header_parsing(httplib_response.msg)\n  File \"/home/ndw/.virtualenvs/pyapi/lib/python3.4/site-packages/requests-2.8.0-py3.4.egg/requests/packages/urllib3/util/response.py\", line 58, in assert_header_parsing\n    raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)\nrequests.packages.urllib3.exceptions.HeaderParsingError: [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ''\n```\n\nIt took me quite a while to work out that they were spurious (because in real life, the server side that is generating the multipart/mixed is more complicated!)\n\nSee also kennethreitz/requests#3001\n## \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(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"}]}