public HttpConnection getConnection(HostConfiguration hostConfiguration) {

    // make sure the host and proxy are correct for this connection
    // close it and set the values if they are not
    if (!hostConfiguration.hostEquals(connection) || !hostConfiguration.proxyEquals(connection)) {

      if (connection.isOpen()) {
        connection.close();
      }

      connection.setHost(hostConfiguration.getHost());
      connection.setPort(hostConfiguration.getPort());
      connection.setProtocol(hostConfiguration.getProtocol());
      connection.setLocalAddress(hostConfiguration.getLocalAddress());

      connection.setProxyHost(hostConfiguration.getProxyHost());
      connection.setProxyPort(hostConfiguration.getProxyPort());
    } else {
      finishLastResponse(connection);
    }

    connectionReleased = false;
    return connection;
  }