@Test void willIgnoreHostHeaderprovided_IfNotIPv4() { headers.add("Host","homestarrunner.com"); request = new HttpGet(URI.create("http: HttpHost host = client.determineTarget(request, headers); assertEquals("zombo.com", host.getHostName()); }
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; }
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; } }
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; }  }
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; }  void setConfigFactory(RequestConfigFactory configFactory); }
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; }  void setConfigFactory(RequestConfigFactory configFactory);  }