6.6 Host Resolution

You may need to resolve the host name of the current server. Micronaut includes an implementation of the HttpHostResolver interface.

The default implementation looks for host information in the following places in order:

  1. The supplied configuration

  2. The Forwarded header

  3. X-Forwarded- headers. If the X-Forwarded-Host header is not present, the other X-Forwarded headers are ignored.

  4. The Host header

  5. The properties on the request URI

  6. The properties on the embedded server URI

The behavior of which headers to pull the relevant data can be changed with the following configuration:

🔗

Table 1. Configuration Properties for HostResolutionConfiguration
PropertyTypeDescription

micronaut.server.host-resolution

HttpServerConfiguration$HostResolutionConfiguration

The host resolution configuration

micronaut.server.host-resolution.host-header

java.lang.String

The header name that stores the host

micronaut.server.host-resolution.protocol-header

java.lang.String

The header name that stores the protocol

micronaut.server.host-resolution.port-header

java.lang.String

The header name that stores the port

micronaut.server.host-resolution.port-in-host

boolean

True if the host header supports a port

micronaut.server.host-resolution.allowed-hosts

java.util.List

The list of allowed host regex patterns. Any resolved

The above configuration also supports an allowed host list. Configuring this list ensures any resolved host matches one of the supplied regular expression patterns. That is useful to prevent host cache poisoning attacks and is recommended to be configured.