Class ConnectionInfo

java.lang.Object
reactor.netty.http.server.ConnectionInfo

public final class ConnectionInfo extends Object
Resolve information about the current connection, including the host (server) address, the remote (client) address and the scheme.

Depending on the chosen factory method, the information can be retrieved directly from the channel or additionally using the "Forwarded", or "X-Forwarded-*" HTTP request headers.

Since:
0.8
Author:
Brian Clozel, Andrey Shlykov
See Also:
  • Method Details

    • getHostAddress

      public @Nullable InetSocketAddress getHostAddress()
      Return the host address of the connection.
      Returns:
      the host address
    • getRemoteAddress

      public @Nullable InetSocketAddress getRemoteAddress()
      Return the remote address of the connection.
      Returns:
      the remote address
    • getScheme

      public String getScheme()
      Return the connection scheme.
      Returns:
      the connection scheme
    • withHostAddress

      public ConnectionInfo withHostAddress(InetSocketAddress hostAddress)
      Return a new ConnectionInfo with the updated host address.
      Parameters:
      hostAddress - the host address
      Returns:
      a new ConnectionInfo
    • withHostAddress

      public ConnectionInfo withHostAddress(InetSocketAddress hostAddress, String hostName, int hostPort)
      Return a new ConnectionInfo with updated host address, host name, and host port information.
      Parameters:
      hostAddress - the updated host address
      hostName - the updated host name
      hostPort - the updated host port
      Returns:
      a new ConnectionInfo
      Since:
      1.0.32
    • withRemoteAddress

      public ConnectionInfo withRemoteAddress(InetSocketAddress remoteAddress)
      Return a new ConnectionInfo with the updated remote address.
      Parameters:
      remoteAddress - the remote address
      Returns:
      a new ConnectionInfo
    • withScheme

      public ConnectionInfo withScheme(String scheme)
      Return a new ConnectionInfo with the updated scheme.
      Parameters:
      scheme - the connection scheme
      Returns:
      a new ConnectionInfo
    • withForwardedPrefix

      public ConnectionInfo withForwardedPrefix(String forwardedPrefix)
      Return a new ConnectionInfo with the forwardedPrefix set.
      Parameters:
      forwardedPrefix - the prefix provided via X-Forwarded-Prefix header
      Returns:
      a new ConnectionInfo
      Since:
      1.1.23
    • getHostName

      public String getHostName()
      Returns the connection host name.
      Returns:
      the connection host name
      Since:
      1.0.32
    • getHostPort

      public int getHostPort()
      Returns the connection host port.
      Returns:
      the connection host port
      Since:
      1.0.32
    • getForwardedPrefix

      public @Nullable String getForwardedPrefix()
      Returns the X-Forwarded-Prefix if it was part of the request headers.
      Returns:
      the X-Forwarded-Prefix
      Since:
      1.1.23
    • getDefaultHostPort

      public static int getDefaultHostPort(String scheme)
      Returns the default host port number based on scheme.
      Parameters:
      scheme - a connection scheme like "http", "https", or "wss"
      Returns:
      the default host port number based on scheme
      Since:
      1.0.32