Clone
 

alexlehm <alexlehm@gmail.com> in Netty

UnknownHostException mentions hostname with search domain added

Motivation:

When a hostname cannot be resolved, the message in the UnknownHostException mentions the hostname with the last attempted search domain appended, which is kind of confusing. I would prefer to see the original hostname supplied to the method in the exception.

Modifications:

Store the pristine hostname in the resolver context and use it to create the exception message instead of the hostname with search domain.

Add unit test to check that the exception does not mention the search domain.

Result:

The exception mentions the unmodified hostname in the message.

Construct LOCALHOST4 and LOCALHOST6 object with hostname "localhost"

Motivation:

When resolving localhost on Windows where the hosts file does not contain a localhost entry by default, the resulting InetAddress object returned by the resolver does not have the hostname set so that getHostName returns the ip address 127.0.0.1. This behaviour is inconsistent with Windows where the hosts file does contain a localhost entry and with Linux in any case. It breaks at least some unit tests.

Modifications:

Create the LOCALHOST4 and LOCALHOST6 objects with hostname localhost in addition to the address.

Add unit test domain localhost to DnsNameResolverTest to check the resolution of localhost with ipv4 at least.

Result:

The resolver returns a InetAddress object for localhost with the hostname localhost in all cases.

Change hosts file resolver to be case-insensitive

Motivation:

Resolving hosts via the /etc/hosts file should be case-insensitive, e.g. localhost and LOCALHOST refer to the same host, this is the same that is applied to dns queries.

Modifications:

Store hosts Map with lowercase keys, lookup the keys as lowercase

Add to unit test for the hosts file parser to use an UPPERCASE file entry

Add unit test for DefaultHostsFileEntriesResolver to resolve both localhost and LOCALHOST

Result:

host resolution for local hosts file should match the rules applied to "getent hosts" or "ping"