public class HostPort
extends java.lang.Object
Parse a string in the form "host:port", handling IPv4 an IPv6 hosts
The System property "org.eclipse.jetty.util.HostPort.STRIP_IPV6" can be set to a boolean value to control of the square brackets are stripped off IPv6 addresses (default false).
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
_host |
private int |
_port |
private static boolean |
STRIP_IPV6 |
Constructor and Description |
---|
HostPort(java.lang.String authority) |
HostPort(java.lang.String host,
int port) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getHost()
Get the host.
|
int |
getPort()
Get the port.
|
int |
getPort(int defaultPort)
Get the port.
|
static java.lang.String |
normalizeHost(java.lang.String host)
Normalize IPv6 address as per https://www.ietf.org/rfc/rfc2732.txt
|
static int |
parsePort(java.lang.String rawPort)
Parse a string representing a port validating it is a valid port value.
|
java.lang.String |
toString() |
private static final boolean STRIP_IPV6
private final java.lang.String _host
private final int _port
public HostPort(java.lang.String host, int port)
public HostPort(java.lang.String authority) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public java.lang.String getHost()
public int getPort()
public int getPort(int defaultPort)
defaultPort,
- the default port to return if a port is not specifiedpublic java.lang.String toString()
toString
in class java.lang.Object
public static java.lang.String normalizeHost(java.lang.String host)
host
- A host namepublic static int parsePort(java.lang.String rawPort) throws java.lang.IllegalArgumentException
rawPort
- the port string.java.lang.IllegalArgumentException