class BaseApacheClient {

    protected static HttpHost determineTarget(final HttpUriRequest request, Headers headers)  {
        HttpHost target = null;

        final URI requestURI = request.getURI();
        if (requestURI.isAbsolute()) {
            target = URIUtils.extractHost(requestURI);
            if (target == null) {
                throw new UnirestException("URI does not specify a valid host name: " + requestURI);
            }
            if(headers.containsKey("Host") && InetAddressUtils.isIPv4Address(target.getHostName())){
                try {
                    InetAddress address = InetAddress.getByName(target.getHostName());
                    target = new HttpHost(address, headers.getFirst("Host"), target.getPort(), target.getSchemeName());
                }catch (UnknownHostException e){
                    throw new UnirestException(e);
                }
            }
        }
        return target;
    }

}