public static HttpHost extractHost(final URI uri) {
        if (uri == null) {
            return null;
        }
        final URIBuilder uriBuilder = new URIBuilder(uri);
        final String scheme = uriBuilder.getScheme();
        final String host = uriBuilder.getHost();
        final int port = uriBuilder.getPort();
        if (!TextUtils.isBlank(host)) {
            try {
                return new HttpHost(scheme, host, port);
            } catch (final IllegalArgumentException ignore) {
            }
        }
        return null;
    }
Extracts target host from the given {@link URI}.

@param uri
@return the target host if the URI is absolute or {@code null} if the URI is
relative or does not contain a valid host name.

@since 4.1
httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java