Skip to content

Bracket IPv6 hosts in the client Host header - #204

Open
abhishekcpp007 wants to merge 1 commit into
python-trio:masterfrom
abhishekcpp007:fix/ipv6-host-header
Open

abhishekcpp007 wants to merge 1 commit into
python-trio:masterfrom
abhishekcpp007:fix/ipv6-host-header

Conversation

@abhishekcpp007

Copy link
Copy Markdown

_url_to_host uses urlsplit().hostname, which strips the brackets, and connect_websocket then builds the header as f'{host}:{port}'. Connecting to ws://[::1]:8000/ sends:

Host: ::1:8000

RFC 6455 4.1 says the Host field follows RFC 3986, so an IPv6 literal needs brackets: [::1]:8000. Endpoint.url in the same file already brackets IPv6 addresses this way.

The header now gets brackets when the host contains :. The bare host still goes to open_tcp_stream and open_ssl_over_tcp_stream, and hostnames and IPv4 addresses are unchanged.

Added test_client_ipv6_host_header, which serves on ::1 with trio.serve_tcp and checks the raw request. It needs IPv6 loopback, which GitHub runners have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant