private HttpURLConnection doConnect(
     final URI uri,
     final String method,
     final byte[] entity,
     final Map<String, List<String>> headers)
     throws HeliosException {
   return delegate.connect(uri, method, entity, headers);
 }
  private HttpURLConnection connectWithCertificateFile(
      final URI ipUri,
      final String method,
      final byte[] entity,
      final Map<String, List<String>> headers)
      throws HeliosException {

    final ClientCertificatePath clientCertificatePath = this.clientCertificatePath.get();
    log.debug("configuring CertificateFileHttpsHandler with {}", clientCertificatePath);

    delegate.setExtraHttpsHandler(
        new CertificateFileHttpsHandler(user, false, clientCertificatePath));

    return doConnect(ipUri, method, entity, headers);
  }
  private HttpURLConnection connectWithIdentities(
      final List<Identity> identities,
      final URI uri,
      final String method,
      final byte[] entity,
      final Map<String, List<String>> headers)
      throws IOException, HeliosException {

    if (identities.isEmpty()) {
      throw new IllegalArgumentException("identities cannot be empty");
    }

    final Queue<Identity> queue = new LinkedList<>(identities);
    HttpURLConnection connection = null;
    while (!queue.isEmpty()) {
      final Identity identity = queue.poll();

      delegate.setExtraHttpsHandler(
          new SshAgentHttpsHandler(user, false, agentProxy.get(), identity));

      connection = doConnect(uri, method, entity, headers);

      // check the status and retry the request if necessary
      final int responseCode = connection.getResponseCode();

      final boolean retryResponse =
          responseCode == HTTP_FORBIDDEN || responseCode == HTTP_UNAUTHORIZED;

      if (retryResponse && !queue.isEmpty()) {
        // there was some sort of security error. if we have any more SSH identities to try,
        // retry with the next available identity
        log.debug(
            "retrying with next SSH identity since {} failed",
            identity == null ? "the previous one" : identity.getComment());
        continue;
      }
      break;
    }
    return connection;
  }