private static HttpHost determineTarget(final HttpUriRequest request) throws ClientProtocolException { // A null target may be acceptable if there is a default target. // Otherwise, the null target is detected in the director. HttpHost target = null; final URI requestURI = request.getURI(); if (requestURI.isAbsolute()) { target = URIUtilsHC4.extractHost(requestURI); if (target == null) { throw new ClientProtocolException("URI does not specify a valid host name: " + requestURI); } } return target; }
/** * Resolves a URI reference against a base URI. Work-around for bug in * java.net.URI (<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>) * * @param baseURI the base URI * @param reference the URI reference * @return the resulting URI */ public static URI resolve(final URI baseURI, final String reference) { return URIUtilsHC4.resolve(baseURI, URI.create(reference)); }
/** * A convenience method for * {@link URIUtilsHC4#rewriteURI(URI, HttpHost, boolean)} that always keeps the * fragment. */ public static URI rewriteURI( final URI uri, final HttpHost target) throws URISyntaxException { return rewriteURI(uri, target, false); }
/** * Resolves a URI reference against a base URI. Work-around for bugs in * java.net.URI (e.g. <http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>) * * @param baseURI the base URI * @param reference the URI reference * @return the resulting URI */ public static URI resolve(final URI baseURI, final URI reference){ Args.notNull(baseURI, "Base URI"); Args.notNull(reference, "Reference URI"); URI ref = reference; final String s = ref.toString(); if (s.startsWith("?")) { return resolveReferenceStartingWithQueryString(baseURI, ref); } final boolean emptyReference = s.length() == 0; if (emptyReference) { ref = URI.create("#"); } URI resolved = baseURI.resolve(ref); if (emptyReference) { final String resolvedString = resolved.toString(); resolved = URI.create(resolvedString.substring(0, resolvedString.indexOf('#'))); } return normalizeSyntax(resolved); }
Asserts.notNull(target, "Target host"); final URI requestURI = new URI(request.getRequestLine().getUri()); final URI absoluteRequestURI = URIUtilsHC4.rewriteURI(requestURI, target, false); uri = URIUtilsHC4.resolve(absoluteRequestURI, uri);
void rewriteRequestURI( final HttpRequestWrapper request, final HttpRoute route) throws ProtocolException { try { URI uri = request.getURI(); if (uri != null) { if (route.getProxyHost() != null && !route.isTunnelled()) { // Make sure the request URI is absolute if (!uri.isAbsolute()) { final HttpHost target = route.getTargetHost(); uri = URIUtilsHC4.rewriteURI(uri, target, true); } else { uri = URIUtilsHC4.rewriteURI(uri); } } else { // Make sure the request URI is relative if (uri.isAbsolute()) { uri = URIUtilsHC4.rewriteURI(uri, null, true); } else { uri = URIUtilsHC4.rewriteURI(uri); } } request.setURI(uri); } } catch (final URISyntaxException ex) { throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex); } }
final HttpHost newTarget = URIUtilsHC4.extractHost(uri); if (newTarget == null) { throw new ProtocolException("Redirect URI does not specify a valid host name: " +
static void rewriteRequestURI( final HttpRequestWrapper request, final HttpRoute route) throws ProtocolException { try { URI uri = request.getURI(); if (uri != null) { // Make sure the request URI is relative if (uri.isAbsolute()) { uri = URIUtilsHC4.rewriteURI(uri, null, true); } else { uri = URIUtilsHC4.rewriteURI(uri); } request.setURI(uri); } } catch (final URISyntaxException ex) { throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex); } }