diff --git a/CHANGES/386.feature b/CHANGES/386.feature new file mode 100644 index 000000000..a44021b7c --- /dev/null +++ b/CHANGES/386.feature @@ -0,0 +1 @@ +Convert host to lowercase on URL building. diff --git a/yarl/_url.py b/yarl/_url.py index 74d0dbd2a..563b53d2a 100644 --- a/yarl/_url.py +++ b/yarl/_url.py @@ -706,6 +706,7 @@ def _encode_host(cls, host): ip, sep, zone = host.partition("%") ip = ip_address(ip) except ValueError: + host = host.lower() # IDNA encoding is slow, # skip it for ASCII-only strings # Don't move the check into _idna_encode() helper @@ -729,6 +730,8 @@ def _encode_host(cls, host): ip, sep, zone = host.partition("%") ip = ip_address(ip) except ValueError: + host = host.lower() + for char in host: if char > "\x7f": break