From 8ad184519b0de8df9283de646abdd0cb87ec50cd Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Thu, 10 Dec 2020 11:32:34 -0500 Subject: [PATCH] Add support for idn --- CHANGELOG.md | 6 ++++++ README.md | 4 ++++ jetforce/app/base.py | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fd0923..cb8e651 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Jetforce Changelog +### v0.8.0 (Unreleased) + +#### Spec Changes + +- Added support for international domain names using IDN encoding. + ### v0.7.0 (2020-12-06) #### Spec Changes diff --git a/README.md b/README.md index deade11..98d0e82 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,10 @@ receive traffic from. For example, if your jetforce server is running on that do not match this hostname will be refused by the server, including URLs that use a direct IP address such as "gemini://174.138.124.169". +IDNs (domain names that contain unicode characters) should be defined using +their ASCII punycode representation. For example, the domain name +*café.mozz.us* should be represented as ``--hostname xn--caf-dma.mozz.us``. + ### Setting the ``host`` The server's host should be set to the local socket that you want to diff --git a/jetforce/app/base.py b/jetforce/app/base.py index e7e0fba..f9651ec 100644 --- a/jetforce/app/base.py +++ b/jetforce/app/base.py @@ -62,7 +62,12 @@ class Request: if self.scheme == "gemini" and url_parts.username: raise ValueError("Invalid userinfo component") - self.hostname = url_parts.hostname + # Convert domain names to punycode for compatibility with URLs that + # contain encoded IDNs (follows RFC 3490). + hostname = url_parts.hostname + hostname = hostname.encode("idna").decode("ascii") + + self.hostname = hostname self.port = url_parts.port self.path = unquote(url_parts.path)