Skip to content

httpclient: Support IDN hostnames in URLs and redirects - #3873

Merged
bdarnell merged 1 commit into
tornadoweb:masterfrom
bdarnell:claude/project-thread-rdyj8b
Nov 13, 2026
Merged

bdarnell merged 1 commit into
tornadoweb:masterfrom
bdarnell:claude/project-thread-rdyj8b

Conversation

@bdarnell

@bdarnell bdarnell commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Convert non-ASCII hostnames with IDNA and percent-encode other non-ASCII
characters as UTF-8, as browsers do, in a shared helper
(httputil._url_to_ascii) used by both simple_httpclient and
curl_httpclient. Both clients now accept IDN URLs (#1490), and
simple_httpclient sends the IDNA form in the Host header instead of raw
latin1.

When following a redirect, simple_httpclient decodes the Location header
as UTF-8 and converts it the same way. This replaces the percent-encoding
of the raw header bytes from #3860, which also percent-encoded the
hostname (#3870). Like browsers, a Location header that is not valid
UTF-8 is now an error. Previously a latin1 hostname happened to work,
but it was sent in the Host header without IDNA conversion and a UTF-8
hostname did not work at all.

The tests move to the common httpclient tests. libcurl follows redirects
itself, so the redirect tests are skipped for curl_httpclient where its
behavior differs: it percent-encodes non-UTF-8 bytes, and converts IDN
hostnames only when built with IDN support.

Fixes #1490
Closes #3870

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01VamvWqdwiBTCFwhDLCbBee

@bdarnell
bdarnell force-pushed the claude/project-thread-rdyj8b branch 2 times, most recently from f6aed97 to 570ed94 Compare November 13, 2026 19:40
Convert non-ASCII hostnames with IDNA and percent-encode other non-ASCII
characters as UTF-8, as browsers do, in a shared helper
(httputil._url_to_ascii) used by both simple_httpclient and
curl_httpclient. Both clients now accept IDN URLs (tornadoweb#1490), and
simple_httpclient sends the IDNA form in the Host header instead of raw
latin1.

When following a redirect, simple_httpclient decodes the Location header
as UTF-8 and converts it the same way. This replaces the percent-encoding
of the raw header bytes from tornadoweb#3860, which also percent-encoded the
hostname (tornadoweb#3870). Like browsers, a Location header that is not valid
UTF-8 is now an error. Previously a latin1 hostname happened to work,
but it was sent in the Host header without IDNA conversion and a UTF-8
hostname did not work at all.

The tests move to the common httpclient tests. libcurl follows redirects
itself, so the redirect tests are skipped for curl_httpclient where its
behavior differs: it percent-encodes non-UTF-8 bytes, and converts IDN
hostnames only when built with IDN support.

Fixes tornadoweb#1490
Closes tornadoweb#3870

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VamvWqdwiBTCFwhDLCbBee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants