Skip to content

Resolve all localhost addresses without querying DNS servers (#16749)#16820

Merged
normanmaurer merged 3 commits into
4.1from
localhost41
May 19, 2026
Merged

Resolve all localhost addresses without querying DNS servers (#16749)#16820
normanmaurer merged 3 commits into
4.1from
localhost41

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

Motivation:

According to RFC 6761, all domains within .localhost. should be resolved to the loopback address without querying DNS servers. This is useful e.g. when you have multiple web servers behind a local reverse proxy and you want to route the requests based on the hostname. Previously, netty would only resolve hostnames specified in the hosts file (or localhost and the machine hostname on windows) without querying DNS servers.

Modifications:

  • localhost and all domains within .localhost. are now directly resolved to the loopback address
  • Replaced isLocalWindowsHost with isLocalHostAddress
  • Replaced LOCALHOST_ADDRESS constant with getLocalHostAddress method to correctly return the correct loopback address based on resolvedAddressTypes
  • Added test that covers all combinations of DnsNameResolverChannelStrategy, ResolvedAddressTypes and various localhost hostnames

Result:

Localhost hostnames are now resolved directly to the loopback address without querying a DNS server. Overriding them in the hosts file is still possible.

Fixes #16744

Motivation:

According to RFC 6761, all domains within .localhost. should be resolved
to the loopback address without querying DNS servers. This is useful
e.g. when you have multiple web servers behind a local reverse proxy and
you want to route the requests based on the hostname. Previously, netty
would only resolve hostnames specified in the hosts file (or localhost
and the machine hostname on windows) without querying DNS servers.

Modifications:

- localhost and all domains within .localhost. are now directly resolved
to the loopback address
- Replaced isLocalWindowsHost with isLocalHostAddress
- Replaced LOCALHOST_ADDRESS constant with getLocalHostAddress method to
correctly return the correct loopback address based on
resolvedAddressTypes
- Added test that covers all combinations of
DnsNameResolverChannelStrategy, ResolvedAddressTypes and various
localhost hostnames

Result:

Localhost hostnames are now resolved directly to the loopback address
without querying a DNS server. Overriding them in the hosts file is
still possible.

Fixes #16744

---------

Co-authored-by: Norman Maurer <norman_maurer@apple.com>
@normanmaurer normanmaurer merged commit bb458bd into 4.1 May 19, 2026
19 checks passed
@normanmaurer normanmaurer deleted the localhost41 branch May 19, 2026 06:17
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.

3 participants