Java 类org.apache.http.client.utils.URIUtilsHC4 实例源码

项目:remote-files-sync    文件:MinimalClientExec.java   
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);
    }
}
项目:Visit    文件:MinimalClientExec.java   
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);
    }
}
项目:ZTLib    文件:MinimalClientExec.java   
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);
    }
}
项目:remote-files-sync    文件:ProtocolExec.java   
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);
    }
}
项目:remote-files-sync    文件:DefaultRedirectStrategy.java   
public URI getLocationURI(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    //get the location header to find out where to redirect to
    final Header locationHeader = response.getFirstHeader("location");
    if (locationHeader == null) {
        // got a redirect response, but no location header
        throw new ProtocolException(
                "Received redirect response " + response.getStatusLine()
                + " but no location header");
    }
    final String location = locationHeader.getValue();
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Redirect requested to location '" + location + "'");
    }

    final RequestConfig config = clientContext.getRequestConfig();

    URI uri = createLocationURI(location);

    // rfc2616 demands the location value be a complete URI
    // Location       = "Location" ":" absoluteURI
    try {
        if (!uri.isAbsolute()) {
            if (!config.isRelativeRedirectsAllowed()) {
                throw new ProtocolException("Relative redirect location '"
                        + uri + "' not allowed");
            }
            // Adjust location URI
            final HttpHost target = clientContext.getTargetHost();
            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);
        }
    } catch (final URISyntaxException ex) {
        throw new ProtocolException(ex.getMessage(), ex);
    }

    RedirectLocationsHC4 redirectLocations = (RedirectLocationsHC4) clientContext.getAttribute(
            HttpClientContext.REDIRECT_LOCATIONS);
    if (redirectLocations == null) {
        redirectLocations = new RedirectLocationsHC4();
        context.setAttribute(HttpClientContext.REDIRECT_LOCATIONS, redirectLocations);
    }
    if (!config.isCircularRedirectsAllowed()) {
        if (redirectLocations.contains(uri)) {
            throw new CircularRedirectException("Circular redirect to '" + uri + "'");
        }
    }
    redirectLocations.add(uri);
    return uri;
}
项目:remote-files-sync    文件:CloseableHttpClient.java   
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;
}
项目:Visit    文件:ProtocolExec.java   
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);
    }
}
项目:Visit    文件:CloseableHttpClient.java   
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;
}
项目:ZTLib    文件:ProtocolExec.java   
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);
    }
}
项目:ZTLib    文件:CloseableHttpClient.java   
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;
}
项目:Visit    文件:DefaultRedirectStrategy.java   
public URI getLocationURI(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    //get the location header to find out where to redirect to
    final Header locationHeader = response.getFirstHeader("location");
    if (locationHeader == null) {
        // got a redirect response, but no location header
        throw new ProtocolException(
                "Received redirect response " + response.getStatusLine()
                + " but no location header");
    }
    final String location = locationHeader.getValue();
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Redirect requested to location '" + location + "'");
    }

    final RequestConfig config = clientContext.getRequestConfig();

    URI uri = createLocationURI(location);

    // rfc2616 demands the location value be a complete URI
    // Location       = "Location" ":" absoluteURI
    try {
        if (!uri.isAbsolute()) {
            if (!config.isRelativeRedirectsAllowed()) {
                throw new ProtocolException("Relative redirect location '"
                        + uri + "' not allowed");
            }
            // Adjust location URI
            final HttpHost target = clientContext.getTargetHost();
            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);
        }
    } catch (final URISyntaxException ex) {
        throw new ProtocolException(ex.getMessage(), ex);
    }

    RedirectLocationsHC4 redirectLocations = (RedirectLocationsHC4) clientContext.getAttribute(
            HttpClientContext.REDIRECT_LOCATIONS);
    if (redirectLocations == null) {
        redirectLocations = new RedirectLocationsHC4();
        context.setAttribute(HttpClientContext.REDIRECT_LOCATIONS, redirectLocations);
    }
    if (!config.isCircularRedirectsAllowed()) {
        if (redirectLocations.contains(uri)) {
            throw new CircularRedirectException("Circular redirect to '" + uri + "'");
        }
    }
    redirectLocations.add(uri);
    return uri;
}
项目:ZTLib    文件:DefaultRedirectStrategy.java   
public URI getLocationURI(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    //get the location header to find out where to redirect to
    final Header locationHeader = response.getFirstHeader("location");
    if (locationHeader == null) {
        // got a redirect response, but no location header
        throw new ProtocolException(
                "Received redirect response " + response.getStatusLine()
                + " but no location header");
    }
    final String location = locationHeader.getValue();
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Redirect requested to location '" + location + "'");
    }

    final RequestConfig config = clientContext.getRequestConfig();

    URI uri = createLocationURI(location);

    // rfc2616 demands the location value be a complete URI
    // Location       = "Location" ":" absoluteURI
    try {
        if (!uri.isAbsolute()) {
            if (!config.isRelativeRedirectsAllowed()) {
                throw new ProtocolException("Relative redirect location '"
                        + uri + "' not allowed");
            }
            // Adjust location URI
            final HttpHost target = clientContext.getTargetHost();
            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);
        }
    } catch (final URISyntaxException ex) {
        throw new ProtocolException(ex.getMessage(), ex);
    }

    RedirectLocationsHC4 redirectLocations = (RedirectLocationsHC4) clientContext.getAttribute(
            HttpClientContext.REDIRECT_LOCATIONS);
    if (redirectLocations == null) {
        redirectLocations = new RedirectLocationsHC4();
        context.setAttribute(HttpClientContext.REDIRECT_LOCATIONS, redirectLocations);
    }
    if (!config.isCircularRedirectsAllowed()) {
        if (redirectLocations.contains(uri)) {
            throw new CircularRedirectException("Circular redirect to '" + uri + "'");
        }
    }
    redirectLocations.add(uri);
    return uri;
}