httpx icon indicating copy to clipboard operation
httpx copied to clipboard

Keep original host on IDNA decode errors

Open mimi89999 opened this issue 2 months ago • 1 comments

Summary

Emoji domains (e.g., https://xn--i-7iq.ws/, https://xn--ls8h.la/) are not allowed by IDNA2008 but are supported by some TLDs, have valid TLS certificates, and work in browsers, curl, and Python's requests library.

Previously, httpx would raise an IDNAError when attempting to decode these Punycode domains, preventing legitimate requests.

This PR modifies the host property to gracefully handle IDNA decode errors by catching idna.IDNAError and keeping the original xn-- encoded form. This allows httpx to work with these real-world emoji domains.

Checklist

  • [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [x] I've updated the documentation accordingly.

mimi89999 avatar Nov 14 '25 11:11 mimi89999

Alternatively, httpx/_models.py could be changed to check self.url.raw_host instead of checking self.url.host. I'm not sure which approach would be preferred. I prefer the approach that I proposed because it matches browser behavior of displaying the raw Punycode on decode errors rather than failing.

mimi89999 avatar Nov 14 '25 11:11 mimi89999