aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jesopo2019-10-18 10:58:24 +0100
committerGravatar jesopo2019-10-18 10:58:24 +0100
commitf64131a10f0ccd710caa94e633f43a9bd1ff1139 (patch)
tree15eb0db922eecd801fda4388b0e238719de5d215 /src
parentpull_request -> merge_request (diff)
signature
support utf8 hostnames by punycode (idna) encoding
Diffstat (limited to 'src')
-rw-r--r--src/utils/http.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/utils/http.py b/src/utils/http.py
index 4a9db07e..936d3118 100644
--- a/src/utils/http.py
+++ b/src/utils/http.py
@@ -1,4 +1,4 @@
-import asyncio, ipaddress, re, signal, socket, traceback, typing
+import asyncio, codecs, ipaddress, re, signal, socket, traceback, typing
import urllib.error, urllib.parse, uuid
import json as _json
import bs4, netifaces, requests
@@ -96,9 +96,17 @@ class Request(object):
self.get_params.update(kwargs)
def set_url(self, url: str):
- if not urllib.parse.urlparse(url).scheme:
- url = "http://%s" % url
- self.url = url
+ parts = urllib.parse.urlparse(url)
+ if not parts.scheme:
+ parts = urllib.parse.urlparse("http://%s" % url)
+
+ netloc = codecs.encode(parts.netloc, "idna").decode("ascii")
+ params = "" if not parts.params else (";%s" % parts.params)
+ query = "" if not parts.query else ("?%s" % parts.query)
+ fragment = "" if not parts.fragment else ("#%s" % parts.fragment)
+
+ self.url = (
+ f"{parts.scheme}://{netloc}{parts.path}{params}{query}{fragment}")
def get_headers(self) -> typing.Dict[str, str]:
headers = self.headers.copy()