aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrjt-gupta <rajat.gupta99924@gmail.com>2019-02-03 00:53:05 +0530
committerrjt-gupta <rajat.gupta99924@gmail.com>2019-02-03 00:53:05 +0530
commitba054b15f367d59139ec78fe03dc1c7d8fb099b5 (patch)
treeaf56a0f3daf31f489c342c3f68f641ffc7d7121e
parentcec8c67465206caa5b4040c5f34050c9ef06b687 (diff)
downloadmitmproxy-ba054b15f367d59139ec78fe03dc1c7d8fb099b5.tar.gz
mitmproxy-ba054b15f367d59139ec78fe03dc1c7d8fb099b5.tar.bz2
mitmproxy-ba054b15f367d59139ec78fe03dc1c7d8fb099b5.zip
url-fix
-rw-r--r--mitmproxy/net/http/url.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/mitmproxy/net/http/url.py b/mitmproxy/net/http/url.py
index f938cb12..d8e14aeb 100644
--- a/mitmproxy/net/http/url.py
+++ b/mitmproxy/net/http/url.py
@@ -21,16 +21,25 @@ def parse(url):
Raises:
ValueError, if the URL is not properly formatted.
"""
- parsed = urllib.parse.urlparse(url)
+ # Size of Ascii character after encoding is 1 byte which is same as its size
+ # But non-Ascii character's size after encoding will be more than its size
+ def ascii_check(l):
+ if len(l) == len(str(l).encode()):
+ return True
+ return False
+
+ if isinstance(url, bytes):
+ url = url.decode()
+ if not ascii_check(url):
+ url = urllib.parse.urlsplit(url)
+ url = list(url)
+ url[3] = urllib.parse.quote(url[3])
+ url = urllib.parse.urlunsplit(url)
+ parsed = urllib.parse.urlparse(url)
if not parsed.hostname:
raise ValueError("No hostname given")
- if isinstance(url, bytes):
- host = parsed.hostname
-
- # this should not raise a ValueError,
- # but we try to be very forgiving here and accept just everything.
else:
host = parsed.hostname.encode("idna")
if isinstance(parsed, urllib.parse.ParseResult):