Class ForwardedHeadersOptions

java.lang.Object
io.vertx.httpproxy.ForwardedHeadersOptions

public class ForwardedHeadersOptions extends Object
Options for configuring forwarded headers support in the proxy.

These headers are used to preserve information about the original client request when proxying through one or more intermediaries.

The proxy can add either X-Forwarded-* headers (de-facto standard) or the RFC 7239 Forwarded header.

  • Field Details

    • DEFAULT_ENABLED

      public static final boolean DEFAULT_ENABLED
      Default enabled = false
      See Also:
    • DEFAULT_FORWARD_FOR

      public static final boolean DEFAULT_FORWARD_FOR
      Default forward for = true
      See Also:
    • DEFAULT_FORWARD_PROTO

      public static final boolean DEFAULT_FORWARD_PROTO
      Default forward proto = true
      See Also:
    • DEFAULT_FORWARD_HOST

      public static final boolean DEFAULT_FORWARD_HOST
      Default forward host = true
      See Also:
    • DEFAULT_FORWARD_PORT

      public static final boolean DEFAULT_FORWARD_PORT
      Default forward port = true
      See Also:
    • DEFAULT_USE_RFC7239

      public static final boolean DEFAULT_USE_RFC7239
      Default use RFC 7239 = false
      See Also:
  • Constructor Details

    • ForwardedHeadersOptions

      public ForwardedHeadersOptions()
      Default constructor.
    • ForwardedHeadersOptions

      public ForwardedHeadersOptions(ForwardedHeadersOptions other)
      Copy constructor.
      Parameters:
      other - the options to copy
    • ForwardedHeadersOptions

      public ForwardedHeadersOptions(JsonObject json)
      Constructor to create an options from JSON.
      Parameters:
      json - the JSON
  • Method Details

    • isEnabled

      public boolean isEnabled()
      Returns:
      whether forwarded headers support is enabled
    • setEnabled

      public ForwardedHeadersOptions setEnabled(boolean enabled)
      Set whether forwarded headers support is enabled.

      When disabled, no forwarded headers will be added to proxied requests.

      Parameters:
      enabled - true to enable forwarded headers
      Returns:
      a reference to this, so the API can be used fluently
    • isForwardFor

      public boolean isForwardFor()
      Returns:
      whether to forward client IP address
    • setForwardFor

      public ForwardedHeadersOptions setForwardFor(boolean forwardFor)
      Set whether to forward the client IP address.

      When enabled, adds the X-Forwarded-For header (or the 'for' parameter in RFC 7239 Forwarded header) with the client's IP address. If the header already exists, the client IP is appended to preserve the proxy chain.

      Parameters:
      forwardFor - true to forward client IP
      Returns:
      a reference to this, so the API can be used fluently
    • isForwardProto

      public boolean isForwardProto()
      Returns:
      whether to forward the original protocol (http/https)
    • setForwardProto

      public ForwardedHeadersOptions setForwardProto(boolean forwardProto)
      Set whether to forward the original protocol (http/https).

      When enabled, adds the X-Forwarded-Proto header (or the 'proto' parameter in RFC 7239 Forwarded header) with the original request scheme.

      Parameters:
      forwardProto - true to forward protocol
      Returns:
      a reference to this, so the API can be used fluently
    • isForwardHost

      public boolean isForwardHost()
      Returns:
      whether to forward the original host
    • setForwardHost

      public ForwardedHeadersOptions setForwardHost(boolean forwardHost)
      Set whether to forward the original host.

      When enabled, adds the X-Forwarded-Host header (or the 'host' parameter in RFC 7239 Forwarded header) with the original request host. This is only added if the host was not already set by ProxyRequest.setAuthority(io.vertx.core.net.HostAndPort).

      Parameters:
      forwardHost - true to forward host
      Returns:
      a reference to this, so the API can be used fluently
    • isForwardPort

      public boolean isForwardPort()
      Returns:
      whether to forward the original port
    • setForwardPort

      public ForwardedHeadersOptions setForwardPort(boolean forwardPort)
      Set whether to forward the original port.

      When enabled, adds the X-Forwarded-Port header with the original request port. This parameter is not included in RFC 7239 Forwarded header.

      Parameters:
      forwardPort - true to forward port
      Returns:
      a reference to this, so the API can be used fluently
    • isUseRfc7239

      public boolean isUseRfc7239()
      Returns:
      whether to use RFC 7239 Forwarded header instead of X-Forwarded-* headers
    • setUseRfc7239

      public ForwardedHeadersOptions setUseRfc7239(boolean useRfc7239)
      Set whether to use RFC 7239 Forwarded header instead of X-Forwarded-* headers.

      When enabled, uses the standardized Forwarded header instead of the de-facto X-Forwarded-For, X-Forwarded-Proto, and X-Forwarded-Host headers. The X-Forwarded-Port header is not included in RFC 7239.

      Parameters:
      useRfc7239 - true to use RFC 7239 format
      Returns:
      a reference to this, so the API can be used fluently
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toJson

      public JsonObject toJson()
      Convert to JSON.
      Returns:
      the JSON