org.apache.hc.core5.http

## Class HttpHost

- java.lang.Object
- - org.apache.hc.core5.http.HttpHost

- All Implemented Interfaces:
    Serializable, NamedEndpoint

      @Contract(threading=IMMUTABLE)
      public final class HttpHost
      extends Object
      implements NamedEndpoint, Serializable

  Component that holds all details needed to describe an HTTP connection to a host. This includes remote host name, port and protocol scheme.
  Since:
    4.0, 5.0 For constructors that take a scheme as an argument, that argument is now the first one.
  See Also:
    `Host`, Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static URIScheme` | `DEFAULT_SCHEME` The default scheme is "http".

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpHost(InetAddress address)` Creates `HttpHost` instance with the default scheme and port and the given inet address.
    `HttpHost(InetAddress address, int port)` Creates `HttpHost` instance with the default scheme and the given inet address and port.
    `HttpHost(String hostname)` Creates `HttpHost` instance with the default scheme and port and the given hostname.
    `HttpHost(String scheme, InetAddress address, int port)` Creates `HttpHost` instance with the given scheme, inet address and port.
    `HttpHost(String scheme, InetAddress address, String hostname, int port)` Creates a new `HttpHost`, specifying all values.
    `HttpHost(String hostname, int port)` Creates `HttpHost` instance with the default scheme and the given hostname and port.
    `HttpHost(String scheme, NamedEndpoint namedEndpoint)`
    `HttpHost(String scheme, String hostname)` Creates `HttpHost` instance with the given hostname and scheme and the default port for that scheme.
    `HttpHost(String scheme, String hostname, int port)` Creates `HttpHost` instance with the given scheme, hostname and port.
    `HttpHost(URIAuthority authority)` Deprecated. Use `HttpHost(String, NamedEndpoint)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static HttpHost` | `create(String s)` Creates `HttpHost` instance from a string.
    `static HttpHost` | `create(URI uri)` Creates an `HttpHost` instance from the scheme, host, and port from the given URI.
    `boolean` | `equals(Object obj)`
    `InetAddress` | `getAddress()` Returns the inet address if explicitly set by a constructor, `null` otherwise.
    `String` | `getHostName()` Returns the host name.
    `int` | `getPort()` Returns the port.
    `String` | `getSchemeName()` Returns the scheme name.
    `int` | `hashCode()`
    `String` | `toHostString()` Obtains the host string, without scheme prefix.
    `String` | `toString()`
    `String` | `toURI()` Return the host URI, as a string.

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_SCHEME

          public static final URIScheme DEFAULT_SCHEME

      The default scheme is "http".

  - ### Constructor Detail

    - #### HttpHost

          public HttpHost(String scheme,
                          InetAddress address,
                          String hostname,
                          int port)

      Creates a new `HttpHost`, specifying all values. Constructor for HttpHost.
      Parameters:
        `scheme` - the name of the scheme. `null` indicates the `default scheme`
        `address` - the inet address. Can be `null`
        `hostname` - the hostname (IP or DNS name)
        `port` - the port number. `-1` indicates the scheme default port.
      Throws:
        `IllegalArgumentException` - If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. `-1` indicates the scheme default port.
      Since:
        5.0

    - #### HttpHost

          public HttpHost(String scheme,
                          String hostname,
                          int port)

      Creates `HttpHost` instance with the given scheme, hostname and port.
      Parameters:
        `scheme` - the name of the scheme. `null` indicates the `default scheme`
        `hostname` - the hostname (IP or DNS name)
        `port` - the port number. `-1` indicates the scheme default port.
      Throws:
        `IllegalArgumentException` - If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. `-1` indicates the scheme default port.

    - #### HttpHost

          public HttpHost(String hostname,
                          int port)

      Creates `HttpHost` instance with the default scheme and the given hostname and port.
      Parameters:
        `hostname` - the hostname (IP or DNS name)
        `port` - the port number. `-1` indicates the scheme default port.
      Throws:
        `IllegalArgumentException` - If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. `-1` indicates the scheme default port.

    - #### HttpHost

          public HttpHost(String scheme,
                          String hostname)

      Creates `HttpHost` instance with the given hostname and scheme and the default port for that scheme.
      Parameters:
        `scheme` - the name of the scheme. `null` indicates the `default scheme`
        `hostname` - the hostname (IP or DNS name)
      Throws:
        `IllegalArgumentException` - If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. `-1` indicates the scheme default port.

    - #### HttpHost

          public HttpHost(String hostname)

      Creates `HttpHost` instance with the default scheme and port and the given hostname.
      Parameters:
        `hostname` - the hostname (IP or DNS name)
      Throws:
        `IllegalArgumentException` - If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. `-1` indicates the scheme default port.

    - #### HttpHost

          public HttpHost(String scheme,
                          InetAddress address,
                          int port)

      Creates `HttpHost` instance with the given scheme, inet address and port.
      Parameters:
        `scheme` - the name of the scheme. `null` indicates the `default scheme`
        `address` - the inet address.
        `port` - the port number. `-1` indicates the scheme default port.
      Throws:
        `IllegalArgumentException` - If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. `-1` indicates the scheme default port.
      Since:
        5.0

    - #### HttpHost

          public HttpHost(InetAddress address,
                          int port)

      Creates `HttpHost` instance with the default scheme and the given inet address and port.
      Parameters:
        `address` - the inet address.
        `port` - the port number. `-1` indicates the scheme default port.
      Throws:
        `IllegalArgumentException` - If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. `-1` indicates the scheme default port.
      Since:
        4.3

    - #### HttpHost

          public HttpHost(InetAddress address)

      Creates `HttpHost` instance with the default scheme and port and the given inet address.
      Parameters:
        `address` - the inet address.
      Throws:
        `IllegalArgumentException` - If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. `-1` indicates the scheme default port.
      Since:
        4.3

    - #### HttpHost

          public HttpHost(String scheme,
                          NamedEndpoint namedEndpoint)

      Throws:
        `IllegalArgumentException` - If the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. `-1` indicates the scheme default port.
      Since:
        5.0

    - #### HttpHost

          @Deprecated
          public HttpHost(URIAuthority authority)

      Deprecated. Use `HttpHost(String, NamedEndpoint)`
      Since:
        5.0

  - ### Method Detail

    - #### create

          public static HttpHost create(String s)
                                 throws URISyntaxException

      Creates `HttpHost` instance from a string. Text may not contain any blanks.
      Throws:
        `URISyntaxException` - Thrown when a string could not be parsed as a URI reference.
      Since:
        4.4

    - #### create

          public static HttpHost create(URI uri)

      Creates an `HttpHost` instance from the scheme, host, and port from the given URI. Other URI elements are ignored.
      Parameters:
        `uri` - scheme, host, and port.
      Returns:
        a new HttpHost
      Since:
        5.0

    - #### getHostName

          public String getHostName()

      Returns the host name.
      Specified by:
        `getHostName` in interface `NamedEndpoint`
      Returns:
        the host name (IP or DNS name)

    - #### getPort

          public int getPort()

      Returns the port.
      Specified by:
        `getPort` in interface `NamedEndpoint`
      Returns:
        the host port, or `-1` if not set

    - #### getSchemeName

          public String getSchemeName()

      Returns the scheme name.
      Returns:
        the scheme name

    - #### getAddress

          public InetAddress getAddress()

      Returns the inet address if explicitly set by a constructor, `null` otherwise.
      Returns:
        the inet address
      Since:
        4.3

    - #### toURI

          public String toURI()

      Return the host URI, as a string.
      Returns:
        the host URI

    - #### toHostString

          public String toHostString()

      Obtains the host string, without scheme prefix.
      Returns:
        the host string, for example `localhost:8080`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`
      See Also:
        `Object.hashCode()`

Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.