public static HttpHost getHost ( HttpRequest request ) { HttpHost httpHost = UriUtils . extractHost ( request . getRequestLine ( ) . getUri ( ) ) ; String scheme = httpHost . getSchemeName ( ) ; String host = httpHost . getHostName ( ) ; int port = httpHost . getPort ( ) ; Header [ ] headers = request . getHeaders ( HttpHeaders . HOST ) ; if ( headers != null && headers . length != 0 ) { String headerValue = headers [ 0 ] . getValue ( ) ; String [ ] splitted = headerValue . split ( ":" ) ; host = splitted [ 0 ] ; if ( splitted . length > 1 ) { port = Integer . parseInt ( splitted [ 1 ] ) ; } else { port = - 1 ; } } return new HttpHost ( host , port , scheme ) ; }
Returns the target host as defined in the Host header or extracted from the request URI .