ForwardedHeaderSupport

This feature allows you to handle reverse proxy headers to get information about the original request when it’s behind a proxy.

  • handles the standard Forwarded header ()

  • XForwardedHeaderSupport handles the non-standard (but standard de-facto) X-Forwarded-Host/X-Forwarded-Server, X-Forwarded-For, X-Forwarded-By, X-Forwarded-Proto/X-Forwarded-Protocol and X-Forwarded-SSL/

or

  1. install(XForwardedHeaderSupport)

You can see all the available request properties on the Requests page.

You can read the raw or local request information, read from the received normal headers and socket properties, that correspond to the proxy request using the request.local property:

You can read the original request information, read from the Forwarded or X-Forwarded-* headers with fallback to the raw headers, that corresponds to original client request using the request.origin property:

  1. val scheme = request.origin.scheme // Determined from X-Forwarded-Proto / X-Forwarded-Protocol / X-Forwarded-SSL
  2. val version = request.origin.version
  3. val port = request.origin.port // Determined from X-Forwarded-Host / X-Forwarded-Server
  4. val method = request.origin.method
  5. val remoteHost = request.origin.remoteHost // Determined from X-Forwarded-For

In the cases where you need the X-Forwarded-By (the interface used for the socket), you can access the raw X-Forwarded properties with:

  1. data class ForwardedHeaderValue(val host: String?, val by: String?, val forParam: String?, val proto: String?, val others: Map<String, String>)

The standard Forwarded header looks like this:

  • by - The interface where the request came in to the proxy server.

  • for - The client that initiated the request and subsequent proxies in a chain of proxies.

  • host - The Host request header field as received by the proxy.

  • - Indicates which protocol was used to make the request (typically “http” or “https”).