code: private void connectTunnel(int connectTimeout, int readTimeout, int writeTimeout, Call call,
        EventListener eventListener) throws IOException {
      Request tunnelRequest = createTunnelRequest();
      HttpUrl url = tunnelRequest.url();
      for (int i = 0; i < MAX_TUNNEL_ATTEMPTS; i++) {
        connectSocket(connectTimeout, readTimeout, call, eventListener);
        tunnelRequest = createTunnel(readTimeout, writeTimeout, tunnelRequest, url);
  
        if (tunnelRequest == null) break; // Tunnel successfully created.
  
        // The proxy decided to close the connection after an auth challenge. We need to create a new
        // connection, but this time with the auth credentials.
        closeQuietly(rawSocket);
        rawSocket = null;
        sink = null;
        source = null;
        eventListener.connectEnd(call, route.socketAddress(), route.proxy(), null);
      }
    }
docs: Does all the work to build an HTTPS connection over a proxy tunnel. The catch here is that a
  proxy server can issue an auth challenge and then close the connection.