org.apache.http

## Class HttpHost

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

- All Implemented Interfaces:
    Serializable, Cloneable

      @Immutable
      public final class HttpHost
      extends Object
      implements Cloneable, Serializable

  Holds all of the variables needed to describe an HTTP connection to a host. This includes remote host name, port and scheme.
  Since:
    4.0
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected InetAddress` | `address`
    `static String` | `DEFAULT_SCHEME_NAME` The default scheme is "http".
    `protected String` | `hostname` The host to use.
    `protected String` | `lcHostname` The lowercase host, for `equals(java.lang.Object)` and `hashCode()`.
    `protected int` | `port` The port to use, defaults to -1 if not set.
    `protected String` | `schemeName` The scheme (lowercased)

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpHost(HttpHost httphost)` Copy constructor for `HttpHost`.
    `HttpHost(InetAddress address)` Creates a new `HttpHost`, with default scheme and port.
    `HttpHost(InetAddress address, int port)` Creates a new `HttpHost`, with default scheme.
    `HttpHost(InetAddress address, int port, String scheme)` Creates a new `HttpHost`, specifying all values.
    `HttpHost(String hostname)` Creates a new `HttpHost`, with default scheme and port.
    `HttpHost(String hostname, int port)` Creates a new `HttpHost`, with default scheme.
    `HttpHost(String hostname, int port, String scheme)` Creates a new `HttpHost`, specifying all values.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `clone()`
    `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

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

- - ### Field Detail

    - #### DEFAULT_SCHEME_NAME

          public static final String DEFAULT_SCHEME_NAME

      The default scheme is "http".
      See Also:
        Constant Field Values

    - #### hostname

          protected final String hostname

      The host to use.

    - #### lcHostname

          protected final String lcHostname

      The lowercase host, for `equals(java.lang.Object)` and `hashCode()`.

    - #### port

          protected final int port

      The port to use, defaults to -1 if not set.

    - #### schemeName

          protected final String schemeName

      The scheme (lowercased)

    - #### address

          protected final InetAddress address

  - ### Constructor Detail

    - #### HttpHost

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

      Creates a new `HttpHost`, specifying all values. Constructor for HttpHost.
      Parameters:
        `hostname` - the hostname (IP or DNS name)
        `port` - the port number. `-1` indicates the scheme default port.
        `scheme` - the name of the scheme. `null` indicates the `default scheme`

    - #### HttpHost

          public HttpHost(String hostname,
                  int port)

      Creates a new `HttpHost`, with default scheme.
      Parameters:
        `hostname` - the hostname (IP or DNS name)
        `port` - the port number. `-1` indicates the scheme default port.

    - #### HttpHost

          public HttpHost(String hostname)

      Creates a new `HttpHost`, with default scheme and port.
      Parameters:
        `hostname` - the hostname (IP or DNS name)

    - #### HttpHost

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

      Creates a new `HttpHost`, specifying all values. Constructor for HttpHost.
      Parameters:
        `address` - the inet address.
        `port` - the port number. `-1` indicates the scheme default port.
        `scheme` - the name of the scheme. `null` indicates the `default scheme`
      Since:
        4.3

    - #### HttpHost

          public HttpHost(InetAddress address,
                  int port)

      Creates a new `HttpHost`, with default scheme.
      Parameters:
        `address` - the inet address.
        `port` - the port number. `-1` indicates the scheme default port.
      Since:
        4.3

    - #### HttpHost

          public HttpHost(InetAddress address)

      Creates a new `HttpHost`, with default scheme and port.
      Parameters:
        `address` - the inet address.
      Since:
        4.3

    - #### HttpHost

          public HttpHost(HttpHost httphost)

      Copy constructor for `HttpHost`.
      Parameters:
        `httphost` - the HTTP host to copy details from

  - ### Method Detail

    - #### getHostName

          public String getHostName()

      Returns the host name.
      Returns:
        the host name (IP or DNS name)

    - #### getPort

          public int getPort()

      Returns the port.
      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()`

    - #### clone

          public Object clone()
                       throws CloneNotSupportedException

      Overrides:
        `clone` in class `Object`
      Throws:
        `CloneNotSupportedException`

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