diff options
| -rw-r--r-- | mitmproxy/net/http/url.py | 24 | 
1 files changed, 3 insertions, 21 deletions
| diff --git a/mitmproxy/net/http/url.py b/mitmproxy/net/http/url.py index f2c8c473..86f65cfd 100644 --- a/mitmproxy/net/http/url.py +++ b/mitmproxy/net/http/url.py @@ -5,22 +5,6 @@ from typing import Tuple  from mitmproxy.net import check -# PY2 workaround -def decode_parse_result(result, enc): -    if hasattr(result, "decode"): -        return result.decode(enc) -    else: -        return urllib.parse.ParseResult(*[x.decode(enc) for x in result]) - - -# PY2 workaround -def encode_parse_result(result, enc): -    if hasattr(result, "encode"): -        return result.encode(enc) -    else: -        return urllib.parse.ParseResult(*[x.encode(enc) for x in result]) - -  def parse(url):      """          URL-parsing function that checks that @@ -47,12 +31,12 @@ def parse(url):          # this should not raise a ValueError,          # but we try to be very forgiving here and accept just everything. -        # decode_parse_result(parsed, "ascii")      else:          host = parsed.hostname.encode("idna") -        parsed = encode_parse_result(parsed, "ascii") +        if isinstance(parsed, urllib.parse.ParseResult): +            parsed = parsed.encode("ascii") -    port = parsed.port +    port = parsed.port  # Returns None if port number invalid in Py3.5. Will throw ValueError in Py3.6      if not port:          port = 443 if parsed.scheme == b"https" else 80 @@ -64,8 +48,6 @@ def parse(url):      if not check.is_valid_host(host):          raise ValueError("Invalid Host") -    if not check.is_valid_port(port): -        raise ValueError("Invalid Port")      return parsed.scheme, host, port, full_path | 
