private static String getFinalResponseUrl ( final HttpClientContext context , final String candidateUrl ) { List < URI > redirectLocations = context . getRedirectLocations ( ) ; if ( redirectLocations != null ) { return redirectLocations . get ( redirectLocations . size ( ) - 1 ) . toString ( ) ; } return candidateUrl ; }
If the HTTP HEAD request was redirected it returns the final redirected URL . If not it returns the original URL of the candidate .