prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Support absolute-form HTTP requests with IPv6 addresses
  ##### Steps to reproduce the problem:
  
  1. MITMDump proxy IPv6 flow
  2. Log
  ```
  172.17.15.1:53074: HTTP protocol error in client request: Bad HTTP request line: b'GET http://[::ffff:180.97.8.37]/mmsns/9KavCVwReibwDKBMmibrWUdVZZbHCQ0bV3R89mboKO6QDls7Sxcl4tfbHvLIHFbj3NASftTH2VAGw/150?tp=wxpc&length=2208&width=1242&idx=1&token=WSEN6qDsKwV8A02w3onOGQYfxnkibdqSOkmHhZGNB4DGicdGyTltMQXCTF7lr4IJR8Jz4lKQBBW47EV1CP33SGjg HTTP/1.1'
  172.17.15.1:53075: HTTP protocol error in client request: Bad HTTP request line: b'GET http://[::ffff:b461:819]/mmcrhead/Q3auHgzwzM606QEH0kXoF60vMh5Iiay7B3DiauET3kCpbBwEfgzhNqOSeJ6y4geORGPxEcKf36Totd4sHQcwvBEg/0 HTTP/1.1'
  ```
  
  
  ##### Any other comments? What have you tried so far?
  No
  
  
  ##### System information
  ```
  Mitmproxy version: 1.0.2
  Python version: 3.6.0
  Platform: Darwin-15.6.0-x86_64-i386-64bit
  SSL version: OpenSSL 1.0.2j  26 Sep 2016
  Mac version: 10.11.6 ('', '', '') x86_6
  ```
  
  
  
  </issue>
  <code>
  [start of mitmproxy/net/check.py]
  1 import re
  2 
  3 # Allow underscore in host name
  4 _label_valid = re.compile(b"(?!-)[A-Z\d\-_]{1,63}(?<!-)$", re.IGNORECASE)
  5 
  6 
  7 def is_valid_host(host: bytes) -> bool:
  8     """
  9         Checks if a hostname is valid.
  10     """
  11     try:
  12         host.decode("idna")
  13     except ValueError:
  14         return False
  15     if len(host) > 255:
  16         return False
  17     if host and host[-1:] == b".":
  18         host = host[:-1]
  19     return all(_label_valid.match(x) for x in host.split(b"."))
  20 
  21 
  22 def is_valid_port(port):
  23     return 0 <= port <= 65535
  24
  [end of mitmproxy/net/check.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/mitmproxy/net/check.py b/mitmproxy/net/check.py
  --- a/mitmproxy/net/check.py
  +++ b/mitmproxy/net/check.py
  @@ -1,3 +1,4 @@
  +import ipaddress
   import re
   
   # Allow underscore in host name
  @@ -6,17 +7,26 @@
   
   def is_valid_host(host: bytes) -> bool:
       """
  -        Checks if a hostname is valid.
  +    Checks if the passed bytes are a valid DNS hostname or an IPv4/IPv6 address.
       """
       try:
           host.decode("idna")
       except ValueError:
           return False
  +    # RFC1035: 255 bytes or less.
       if len(host) > 255:
           return False
       if host and host[-1:] == b".":
           host = host[:-1]
  -    return all(_label_valid.match(x) for x in host.split(b"."))
  +    # DNS hostname
  +    if all(_label_valid.match(x) for x in host.split(b".")):
  +        return True
  +    # IPv4/IPv6 address
  +    try:
  +        ipaddress.ip_address(host.decode('idna'))
  +        return True
  +    except ValueError:
  +        return False
   
   
   def is_valid_port(port):
  
verification_info: {"golden_diff": "diff --git a/mitmproxy/net/check.py b/mitmproxy/net/check.py\n--- a/mitmproxy/net/check.py\n+++ b/mitmproxy/net/check.py\n@@ -1,3 +1,4 @@\n+import ipaddress\n import re\n \n # Allow underscore in host name\n@@ -6,17 +7,26 @@\n \n def is_valid_host(host: bytes) -> bool:\n     \"\"\"\n-        Checks if a hostname is valid.\n+    Checks if the passed bytes are a valid DNS hostname or an IPv4/IPv6 address.\n     \"\"\"\n     try:\n         host.decode(\"idna\")\n     except ValueError:\n         return False\n+    # RFC1035: 255 bytes or less.\n     if len(host) > 255:\n         return False\n     if host and host[-1:] == b\".\":\n         host = host[:-1]\n-    return all(_label_valid.match(x) for x in host.split(b\".\"))\n+    # DNS hostname\n+    if all(_label_valid.match(x) for x in host.split(b\".\")):\n+        return True\n+    # IPv4/IPv6 address\n+    try:\n+        ipaddress.ip_address(host.decode('idna'))\n+        return True\n+    except ValueError:\n+        return False\n \n \n def is_valid_port(port):\n", "issue": "Support absolute-form HTTP requests with IPv6 addresses\n##### Steps to reproduce the problem:\r\n\r\n1. MITMDump proxy IPv6 flow\r\n2. Log\r\n```\r\n172.17.15.1:53074: HTTP protocol error in client request: Bad HTTP request line: b'GET http://[::ffff:180.97.8.37]/mmsns/9KavCVwReibwDKBMmibrWUdVZZbHCQ0bV3R89mboKO6QDls7Sxcl4tfbHvLIHFbj3NASftTH2VAGw/150?tp=wxpc&length=2208&width=1242&idx=1&token=WSEN6qDsKwV8A02w3onOGQYfxnkibdqSOkmHhZGNB4DGicdGyTltMQXCTF7lr4IJR8Jz4lKQBBW47EV1CP33SGjg HTTP/1.1'\r\n172.17.15.1:53075: HTTP protocol error in client request: Bad HTTP request line: b'GET http://[::ffff:b461:819]/mmcrhead/Q3auHgzwzM606QEH0kXoF60vMh5Iiay7B3DiauET3kCpbBwEfgzhNqOSeJ6y4geORGPxEcKf36Totd4sHQcwvBEg/0 HTTP/1.1'\r\n```\r\n\r\n\r\n##### Any other comments? What have you tried so far?\r\nNo\r\n\r\n\r\n##### System information\r\n```\r\nMitmproxy version: 1.0.2\r\nPython version: 3.6.0\r\nPlatform: Darwin-15.6.0-x86_64-i386-64bit\r\nSSL version: OpenSSL 1.0.2j  26 Sep 2016\r\nMac version: 10.11.6 ('', '', '') x86_6\r\n```\r\n\r\n\n", "before_files": [{"content": "import re\n\n# Allow underscore in host name\n_label_valid = re.compile(b\"(?!-)[A-Z\\d\\-_]{1,63}(?<!-)$\", re.IGNORECASE)\n\n\ndef is_valid_host(host: bytes) -> bool:\n    \"\"\"\n        Checks if a hostname is valid.\n    \"\"\"\n    try:\n        host.decode(\"idna\")\n    except ValueError:\n        return False\n    if len(host) > 255:\n        return False\n    if host and host[-1:] == b\".\":\n        host = host[:-1]\n    return all(_label_valid.match(x) for x in host.split(b\".\"))\n\n\ndef is_valid_port(port):\n    return 0 <= port <= 65535\n", "path": "mitmproxy/net/check.py"}]}