public Response call(String httpMethod, URL url, Request request) throws IOException {
    if (!isHttpsProtocol(url)) {
      if (enableHttpAndInsecureFailover) { // HTTP requested. We only care if HTTP is enabled.
        return call(httpMethod, url, request, getHttpTransport(true), true);
      }
      throw new SSLException("insecure HTTP connection not allowed: " + url);
    }

    Optional<Response> fastPathResponse = followFailoverHistory(httpMethod, url, request);
    if (fastPathResponse.isPresent()) {
      return fastPathResponse.get();
    }

    try {
      return call(httpMethod, url, request, getHttpTransport(true), !enableHttpAndInsecureFailover);

    } catch (SSLException ex) {
      if (!enableHttpAndInsecureFailover) {
        throw ex;
      }

      try {
        logInsecureHttpsFailover(url);
        Response response = call(httpMethod, url, request, getHttpTransport(false), false);
        failoverHistory.put(url.getHost() + ":" + url.getPort(), Failover.INSECURE_HTTPS);
        return response;

      } catch (SSLException ignored) { // This is usually when the server is plain-HTTP.
        logHttpFailover(url);
        Response response = call(httpMethod, toHttp(url), request, getHttpTransport(true), true);
        failoverHistory.put(url.getHost() + ":" + url.getPort(), Failover.HTTP);
        return response;
      }

    } catch (ConnectException ex) {
      // It is observed that Open/Oracle JDKs sometimes throw SocketTimeoutException but other times
      // ConnectException for connection timeout. (Could be a JDK bug.) Note SocketTimeoutException
      // does not extend ConnectException (or vice versa), and we want to be consistent to error out
      // on timeouts: https://github.com/GoogleContainerTools/jib/issues/1895#issuecomment-527544094
      if (ex.getMessage() == null || !ex.getMessage().contains("timed out")) {
        // Fall back to HTTP only if "url" had no port specified (i.e., we tried the default HTTPS
        // port 443) and we could not connect to 443. It's worth trying port 80.
        if (enableHttpAndInsecureFailover && isHttpsProtocol(url) && url.getPort() == -1) {
          logHttpFailover(url);
          Response response = call(httpMethod, toHttp(url), request, getHttpTransport(true), true);
          failoverHistory.put(url.getHost() + ":" + url.getPort(), Failover.HTTP);
          return response;
        }
      }
      throw ex;
    }
  }
Sends the request.

@param httpMethod the HTTP request method
@param url endpoint URL
@param request the request to send
@return the response to the sent request
@throws IOException if building the HTTP request fails.
jib-core/src/main/java/com/google/cloud/tools/jib/http/FailoverHttpClient.java