Java Code Examples for net.lightbody.bmp.util.BrowserMobHttpUtil#removeMatchingPort()

The following examples show how to use net.lightbody.bmp.util.BrowserMobHttpUtil#removeMatchingPort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpsHostCaptureFilter.java    From CapturePacket with MIT License 6 votes vote down vote up
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
    if (httpObject instanceof HttpRequest) {
        HttpRequest httpRequest = (HttpRequest) httpObject;

        if (ProxyUtils.isCONNECT(httpRequest)) {
            Attribute<String> hostname = ctx.attr(AttributeKey.<String>valueOf(HttpsAwareFiltersAdapter.HOST_ATTRIBUTE_NAME));
            String hostAndPort = httpRequest.getUri();

            // CONNECT requests contain the port, even when using the default port. a sensible default is to remove the
            // default port, since in most cases it is not explicitly specified and its presence (in a HAR file, for example)
            // would be unexpected.
            String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(hostAndPort, 443);
            hostname.set(hostNoDefaultPort);
        }
    }

    return null;
}
 
Example 2
Source File: HttpsHostCaptureFilter.java    From Dream-Catcher with MIT License 6 votes vote down vote up
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
    if (httpObject instanceof HttpRequest) {
        HttpRequest httpRequest = (HttpRequest) httpObject;

        if (ProxyUtils.isCONNECT(httpRequest)) {
            Attribute<String> hostname = ctx.attr(AttributeKey.<String>valueOf(HttpsAwareFiltersAdapter.HOST_ATTRIBUTE_NAME));
            String hostAndPort = httpRequest.getUri();

            // CONNECT requests contain the port, even when using the default port. a sensible default is to remove the
            // default port, since in most cases it is not explicitly specified and its presence (in a HAR file, for example)
            // would be unexpected.
            String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(hostAndPort, 443);
            hostname.set(hostNoDefaultPort);
        }
    }

    return null;
}
 
Example 3
Source File: HttpsHostCaptureFilter.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
    if (httpObject instanceof HttpRequest) {
        HttpRequest httpRequest = (HttpRequest) httpObject;

        if (ProxyUtils.isCONNECT(httpRequest)) {
            Attribute<String> hostname = ctx.attr(AttributeKey.<String>valueOf(HttpsAwareFiltersAdapter.HOST_ATTRIBUTE_NAME));
            String hostAndPort = httpRequest.getUri();

            // CONNECT requests contain the port, even when using the default port. a sensible default is to remove the
            // default port, since in most cases it is not explicitly specified and its presence (in a HAR file, for example)
            // would be unexpected.
            String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(hostAndPort, 443);
            hostname.set(hostNoDefaultPort);
        }
    }

    return null;
}
 
Example 4
Source File: HttpsAwareFiltersAdapter.java    From CapturePacket with MIT License 5 votes vote down vote up
/**
 * Returns the full, absolute URL of the specified request for both HTTP and HTTPS URLs. The request may reflect
 * modifications from this or other filters. This filter instance must be currently handling the specified request;
 * otherwise the results are undefined.
 *
 * @param modifiedRequest a possibly-modified version of the request currently being processed
 * @return the full URL of the request, including scheme, host, port, path, and query parameters
 */
public String getFullUrl(HttpRequest modifiedRequest) {
    // special case: for HTTPS requests, the full URL is scheme (https://) + the URI of this request
    if (ProxyUtils.isCONNECT(modifiedRequest)) {
        // CONNECT requests contain the default port, even if it isn't specified on the request.
        String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(modifiedRequest.getUri(), 443);
        return "https://" + hostNoDefaultPort;
    }

    // To get the full URL, we need to retrieve the Scheme, Host + Port, Path, and Query Params from the request.
    // If the request URI starts with http:// or https://, it is already a full URL and can be returned directly.
    if (HttpUtil.startsWithHttpOrHttps(modifiedRequest.getUri())) {
        return modifiedRequest.getUri();
    }

    // The URI did not include the scheme and host, so examine the request to obtain them:
    // Scheme: the scheme (HTTP/HTTPS) are based on the type of connection, obtained from isHttps()
    // Host and Port: available for HTTP and HTTPS requests using the getHostAndPort() helper method.
    // Path + Query Params: since the request URI doesn't start with the scheme, we can safely assume that the URI
    //    contains only the path and query params.
    String hostAndPort = getHostAndPort(modifiedRequest);
    String path = modifiedRequest.getUri();
    String url;
    if (isHttps()) {
        url = "https://" + hostAndPort + path;
    } else {
        url = "http://" + hostAndPort + path;
    }
    return url;
}
 
Example 5
Source File: HttpsAwareFiltersAdapter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
/**
 * Returns the full, absolute URL of the specified request for both HTTP and HTTPS URLs. The request may reflect
 * modifications from this or other filters. This filter instance must be currently handling the specified request;
 * otherwise the results are undefined.
 *
 * @param modifiedRequest a possibly-modified version of the request currently being processed
 * @return the full URL of the request, including scheme, host, port, path, and query parameters
 */
public String getFullUrl(HttpRequest modifiedRequest) {
    // special case: for HTTPS requests, the full URL is scheme (https://) + the URI of this request
    if (ProxyUtils.isCONNECT(modifiedRequest)) {
        // CONNECT requests contain the default port, even if it isn't specified on the request.
        String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(modifiedRequest.getUri(), 443);
        return "https://" + hostNoDefaultPort;
    }

    // To get the full URL, we need to retrieve the Scheme, Host + Port, Path, and Query Params from the request.
    // If the request URI starts with http:// or https://, it is already a full URL and can be returned directly.
    if (HttpUtil.startsWithHttpOrHttps(modifiedRequest.getUri())) {
        return modifiedRequest.getUri();
    }

    // The URI did not include the scheme and host, so examine the request to obtain them:
    // Scheme: the scheme (HTTP/HTTPS) are based on the type of connection, obtained from isHttps()
    // Host and Port: available for HTTP and HTTPS requests using the getHostAndPort() helper method.
    // Path + Query Params: since the request URI doesn't start with the scheme, we can safely assume that the URI
    //    contains only the path and query params.
    String hostAndPort = getHostAndPort(modifiedRequest);
    String path = modifiedRequest.getUri();
    String url;
    if (isHttps()) {
        url = "https://" + hostAndPort + path;
    } else {
        url = "http://" + hostAndPort + path;
    }
    return url;
}
 
Example 6
Source File: HttpsAwareFiltersAdapter.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
/**
 * Returns the full, absolute URL of the specified request for both HTTP and HTTPS URLs. The request may reflect
 * modifications from this or other filters. This filter instance must be currently handling the specified request;
 * otherwise the results are undefined.
 *
 * @param modifiedRequest a possibly-modified version of the request currently being processed
 * @return the full URL of the request, including scheme, host, port, path, and query parameters
 */
public String getFullUrl(HttpRequest modifiedRequest) {
    // special case: for HTTPS requests, the full URL is scheme (https://) + the URI of this request
    if (ProxyUtils.isCONNECT(modifiedRequest)) {
        // CONNECT requests contain the default port, even if it isn't specified on the request.
        String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(modifiedRequest.getUri(), 443);
        return "https://" + hostNoDefaultPort;
    }

    // To get the full URL, we need to retrieve the Scheme, Host + Port, Path, and Query Params from the request.
    // If the request URI starts with http:// or https://, it is already a full URL and can be returned directly.
    if (HttpUtil.startsWithHttpOrHttps(modifiedRequest.getUri())) {
        return modifiedRequest.getUri();
    }

    // The URI did not include the scheme and host, so examine the request to obtain them:
    // Scheme: the scheme (HTTP/HTTPS) are based on the type of connection, obtained from isHttps()
    // Host and Port: available for HTTP and HTTPS requests using the getHostAndPort() helper method.
    // Path + Query Params: since the request URI doesn't start with the scheme, we can safely assume that the URI
    //    contains only the path and query params.
    String hostAndPort = getHostAndPort(modifiedRequest);
    String path = modifiedRequest.getUri();
    String url;
    if (isHttps()) {
        url = "https://" + hostAndPort + path;
    } else {
        url = "http://" + hostAndPort + path;
    }
    return url;
}