Class HostPort

java.lang.Object
org.eclipse.jetty.util.HostPort

public class HostPort extends Object

Parse an authority string (in the form host:port) into host and port, handling IPv4 and IPv6 host formats as defined in RFC 2732

  • Constructor Details

  • Method Details

    • unsafe

      public static HostPort unsafe(String authority)
      Create a HostPort from an unsafe (and not validated) authority.

      There are no validations performed against the provided authority. It is quite possible to end up with HostPort that cannot be used to generate valid URL, URI, InetSocketAddress, Location header, etc.

      Parameters:
      authority - raw authority
      Returns:
      the HostPort
    • isValidIpAddress

      protected boolean isValidIpAddress(String ip)
    • isValidHostName

      protected boolean isValidHostName(String name)
    • getHost

      @ManagedAttribute("host") public String getHost()
      Get the host.
      Returns:
      the host
    • getPort

      @ManagedAttribute("port") public int getPort()
      Get the port.
      Returns:
      the port
    • getPort

      public int getPort(int defaultPort)
      Get the port or the given default port.
      Parameters:
      defaultPort - , the default port to return if a port is not specified
      Returns:
      the port
    • hasHost

      public boolean hasHost()
    • hasPort

      public boolean hasPort()
    • toString

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

      public static String normalizeHost(String host)
      Normalizes IPv6 address as per RFC 2732 and RFC 6874, surrounding with square brackets if they are absent.
      Parameters:
      host - a host name, IPv4 address, IPv6 address or IPv6 literal
      Returns:
      a host name or an IPv4 address or an IPv6 literal (not an IPv6 address)
    • parsePort

      public static int parsePort(String rawPort) throws IllegalArgumentException
      Parse a string representing a port validating it is a valid port value.
      Parameters:
      rawPort - the port string.
      Returns:
      the integer value for the port.
      Throws:
      IllegalArgumentException - if the port is invalid