net.lightbody.bmp.core.har.HarRequest Java Examples

The following examples show how to use net.lightbody.bmp.core.har.HarRequest. 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: ContentTabHolder.java    From CapturePacket with MIT License 6 votes vote down vote up
private List<? extends INameValue> getOverViewList(HarEntry harEntry) {
    ArrayList<HarNameValuePair> pairs = new ArrayList<>();
    HarRequest harRequest = harEntry.getRequest();
    HarResponse harResponse = harEntry.getResponse();
    if (harRequest != null) {
        String url = harRequest.getUrl();
        try {
            url = URLDecoder.decode(url, "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        pairs.add(new HarNameValuePair("URL", url));

        pairs.add(new HarNameValuePair("Method", harRequest.getMethod()));
    }
    if (harResponse != null) {
        pairs.add(new HarNameValuePair("Code", harResponse.getStatus() + ""));
        pairs.add(new HarNameValuePair("Size", harResponse.getBodySize() + "Bytes"));
    }
    pairs.add(new HarNameValuePair("TotalTime", harEntry.getTime() + "ms"));
    return pairs;
}
 
Example #2
Source File: HarCaptureFilter.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
/**
 * Creates a HarRequest object using the method, url, and HTTP version of the specified request.
 *
 * @param httpRequest HTTP request on which the HarRequest will be based
 * @return a new HarRequest object
 */
private HarRequest createHarRequestForHttpRequest(HttpRequest httpRequest) {
    // the HAR spec defines the request.url field as:
    //     url [string] - Absolute URL of the request (fragments are not included).
    // the URI on the httpRequest may only identify the path of the resource, so find the full URL.
    // the full URL consists of the scheme + host + port (if non-standard) + path + query params + fragment.
    String url = getFullUrl(httpRequest);

    return new HarRequest(httpRequest.getMethod().toString(), url, httpRequest.getProtocolVersion().text());
}
 
Example #3
Source File: HarCaptureFilter.java    From CapturePacket with MIT License 5 votes vote down vote up
/**
 * Creates a HarRequest object using the method, url, and HTTP version of the specified request.
 *
 * @param httpRequest HTTP request on which the HarRequest will be based
 * @return a new HarRequest object
 */
private HarRequest createHarRequestForHttpRequest(HttpRequest httpRequest) {
    // the HAR spec defines the request.url field as:
    //     url [string] - Absolute URL of the request (fragments are not included).
    // the URI on the httpRequest may only identify the path of the resource, so find the full URL.
    // the full URL consists of the scheme + host + port (if non-standard) + path + query params + fragment.
    String url = getFullUrl(httpRequest);

    return new HarRequest(httpRequest.getMethod().toString(), url, httpRequest.getProtocolVersion().text());
}
 
Example #4
Source File: HarCaptureFilter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
/**
 * Creates a DCRequest object using the method, url, and HTTP version of the specified request.
 *
 * @param httpRequest HTTP request on which the DCRequest will be based
 * @return a new DCRequest object
 */
private HarRequest createHarRequestForHttpRequest(HttpRequest httpRequest) {
    // the HAR spec defines the request.url field as:
    //     url [string] - Absolute URL of the request (fragments are not included).
    // the URI on the httpRequest may only identify the path of the resource, so find the full URL.
    // the full URL consists of the scheme + host + port (if non-standard) + path + query params + fragment.
    String url = getFullUrl(httpRequest);

    return new HarRequest(httpRequest.getMethod().toString(), url, httpRequest.getProtocolVersion().text());
}
 
Example #5
Source File: DCRequest.java    From Dream-Catcher with MIT License 4 votes vote down vote up
public HarRequest getRequest() {
    return harEntry.getRequest();
}
 
Example #6
Source File: HarCaptureFilter.java    From AndroidHttpCapture with MIT License 4 votes vote down vote up
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
    // if a ServerResponseCaptureFilter is configured, delegate to it to collect the client request. if it is not
    // configured, we still need to capture basic information (timings, possibly client headers, etc.), just not content.
    if (requestCaptureFilter != null) {
        requestCaptureFilter.clientToProxyRequest(httpObject);
    }

    if (httpObject instanceof HttpRequest) {
        // link the object up now, before we make the request, so that if we get cut off (ie: favicon.ico request and browser shuts down)
        // we still have the attempt associated, even if we never got a response
        harEntry.setStartedDateTime(new Date());
        har.getLog().addEntry(harEntry);

        HttpRequest httpRequest = (HttpRequest) httpObject;
        this.capturedOriginalRequest = httpRequest;

        // associate this request's HarRequest object with the har entry
        HarRequest request = createHarRequestForHttpRequest(httpRequest);
        harEntry.setRequest(request);

        // create a "no response received" HarResponse, in case the connection is interrupted, terminated, or the response is not received
        // for any other reason. having a "default" HarResponse prevents us from generating an invalid HAR.
        HarResponse defaultHarResponse = HarCaptureUtil.createHarResponseForFailure();
        defaultHarResponse.setError(HarCaptureUtil.getNoResponseReceivedErrorMessage());
        harEntry.setResponse(defaultHarResponse);

        captureQueryParameters(httpRequest);
        // not capturing user agent: in many cases, it doesn't make sense to capture at the HarLog level, since the proxy could be
        // serving requests from many different clients with various user agents. clients can turn on the REQUEST_HEADERS capture type
        // in order to capture the User-Agent header, if desired.
        captureRequestHeaderSize(httpRequest);

        if (dataToCapture.contains(CaptureType.REQUEST_COOKIES)) {
            captureRequestCookies(httpRequest);
        }

        if (dataToCapture.contains(CaptureType.REQUEST_HEADERS)) {
            captureRequestHeaders(httpRequest);
        }

        // The HTTP CONNECT to the proxy server establishes the SSL connection to the remote server, but the
        // HTTP CONNECT is not recorded in a separate HarEntry (except in case of error). Instead, the ssl and
        // connect times are recorded in the first request between the client and remote server after the HTTP CONNECT.
        captureConnectTiming();
    }

    if (httpObject instanceof HttpContent) {
        HttpContent httpContent = (HttpContent) httpObject;

        captureRequestSize(httpContent);
    }

    if (httpObject instanceof LastHttpContent) {
        LastHttpContent lastHttpContent = (LastHttpContent) httpObject;
        if (dataToCapture.contains(CaptureType.REQUEST_HEADERS)) {
            captureTrailingHeaders(lastHttpContent);
        }

        if (dataToCapture.contains(CaptureType.REQUEST_CONTENT)) {
            captureRequestContent(requestCaptureFilter.getHttpRequest(), requestCaptureFilter.getFullRequestContents());
        }

        harEntry.getRequest().setBodySize(requestBodySize.get());
    }

    return null;
}
 
Example #7
Source File: HttpConnectHarCaptureFilter.java    From AndroidHttpCapture with MIT License 4 votes vote down vote up
/**
 * Creates a {@link HarEntry} for a failed CONNECT request. Initializes and populates the entry, including the
 * {@link HarRequest}, {@link HarResponse}, and {@link HarTimings}. (Note: only successful timing information is
 * populated in the timings object; the calling method must populate the timing information for the final, failed
 * step. For example, if DNS resolution failed, this method will populate the network 'blocked' time, but not the DNS
 * time.) Populates the specified errorMessage in the {@link HarResponse}'s error field.
 *
 * @param errorMessage error message to place in the har response
 * @return a new HAR entry
 */
private HarEntry createHarEntryForFailedCONNECT(String errorMessage) {
    HarEntry harEntry = new HarEntry(currentPageRef);
    harEntry.setStartedDateTime(requestStartTime);

    HarRequest request = createRequestForFailedConnect(originalRequest);
    harEntry.setRequest(request);

    HarResponse response = HarCaptureUtil.createHarResponseForFailure();
    harEntry.setResponse(response);

    response.setError(errorMessage);

    populateTimingsForFailedCONNECT(harEntry);

    populateServerIpAddress(harEntry);


    return harEntry;
}
 
Example #8
Source File: HarCaptureFilter.java    From Dream-Catcher with MIT License 4 votes vote down vote up
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
    // if a ServerResponseCaptureFilter is configured, delegate to it to collect the client request. if it is not
    // configured, we still need to capture basic information (timings, possibly client headers, etc.), just not content.
    Log.e("Capture", "clientToProxyRequest " + harEntry.getId());
    if (requestCaptureFilter != null) {
        requestCaptureFilter.clientToProxyRequest(httpObject);
    }

    if (httpObject instanceof HttpRequest) {
        // link the object up now, before we make the request, so that if we get cut off (ie: favicon.ico request and browser shuts down)
        // we still have the attempt associated, even if we never got a response
        harEntry.setStartedDateTime(new Date());
        har.getLog().addEntry(harEntry);

        HttpRequest httpRequest = (HttpRequest) httpObject;
        this.capturedOriginalRequest = httpRequest;

        // associate this request's DCRequest object with the har entry
        HarRequest request = createHarRequestForHttpRequest(httpRequest);
        harEntry.setRequest(request);

        // create a "no response received" DCResponse, in case the connection is interrupted, terminated, or the response is not received
        // for any other reason. having a "default" DCResponse prevents us from generating an invalid HAR.
        HarResponse defaultHarResponse = HarCaptureUtil.createHarResponseForFailure();
        defaultHarResponse.setError(HarCaptureUtil.getNoResponseReceivedErrorMessage());
        harEntry.setResponse(defaultHarResponse);

        captureQueryParameters(httpRequest);
        // not capturing user agent: in many cases, it doesn't make sense to capture at the HarLog level, since the proxy could be
        // serving requests from many different clients with various user agents. clients can turn on the REQUEST_HEADERS capture type
        // in order to capture the User-Agent header, if desired.
        captureRequestHeaderSize(httpRequest);

        if (dataToCapture.contains(CaptureType.REQUEST_COOKIES)) {
            captureRequestCookies(httpRequest);
        }

        if (dataToCapture.contains(CaptureType.REQUEST_HEADERS)) {
            captureRequestHeaders(httpRequest);
        }

        // The HTTP CONNECT to the proxy server establishes the SSL connection to the remote server, but the
        // HTTP CONNECT is not recorded in a separate HarEntry (except in case of error). Instead, the ssl and
        // connect times are recorded in the first request between the client and remote server after the HTTP CONNECT.
        captureConnectTiming();
    }

    if (httpObject instanceof HttpContent) {
        HttpContent httpContent = (HttpContent) httpObject;

        captureRequestSize(httpContent);
    }

    if (httpObject instanceof LastHttpContent) {
        LastHttpContent lastHttpContent = (LastHttpContent) httpObject;
        if (dataToCapture.contains(CaptureType.REQUEST_HEADERS)) {
            captureTrailingHeaders(lastHttpContent);
        }

        if (dataToCapture.contains(CaptureType.REQUEST_CONTENT)) {
            captureRequestContent(requestCaptureFilter.getHttpRequest(), requestCaptureFilter.getFullRequestContents());
        }

        harRequest.getRequest().setBodySize(requestBodySize.get());
    }

    return null;
}
 
Example #9
Source File: HttpConnectHarCaptureFilter.java    From Dream-Catcher with MIT License 4 votes vote down vote up
/**
 * Creates a {@link HarEntry} for a failed CONNECT request. Initializes and populates the entry, including the
 * {@link HarRequest}, {@link HarResponse}, and {@link HarTimings}. (Note: only successful timing information is
 * populated in the timings object; the calling method must populate the timing information for the final, failed
 * step. For example, if DNS resolution failed, this method will populate the network 'blocked' time, but not the DNS
 * time.) Populates the specified errorMessage in the {@link HarResponse}'s error field.
 *
 * @param errorMessage error message to place in the har response
 * @return a new HAR entry
 */
private HarEntry createHarEntryForFailedCONNECT(String errorMessage) {
    HarEntry harEntry = new HarEntry(currentPageRef);
    harEntry.setStartedDateTime(requestStartTime);

    HarRequest request = createRequestForFailedConnect(originalRequest);
    harEntry.setRequest(request);

    HarResponse response = HarCaptureUtil.createHarResponseForFailure();
    harEntry.setResponse(response);

    response.setError(errorMessage);

    populateTimingsForFailedCONNECT(harEntry);

    populateServerIpAddress(harEntry);


    return harEntry;
}
 
Example #10
Source File: HttpConnectHarCaptureFilter.java    From CapturePacket with MIT License 4 votes vote down vote up
/**
 * Creates a {@link HarEntry} for a failed CONNECT request. Initializes and populates the entry, including the
 * {@link HarRequest}, {@link HarResponse}, and {@link HarTimings}. (Note: only successful timing information is
 * populated in the timings object; the calling method must populate the timing information for the final, failed
 * step. For example, if DNS resolution failed, this method will populate the network 'blocked' time, but not the DNS
 * time.) Populates the specified errorMessage in the {@link HarResponse}'s error field.
 *
 * @param errorMessage error message to place in the har response
 * @return a new HAR entry
 */
private HarEntry createHarEntryForFailedCONNECT(String errorMessage) {
    HarEntry harEntry = new HarEntry(currentPageRef);
    harEntry.setStartedDateTime(requestStartTime);

    HarRequest request = createRequestForFailedConnect(originalRequest);
    harEntry.setRequest(request);

    HarResponse response = HarCaptureUtil.createHarResponseForFailure();
    harEntry.setResponse(response);

    response.setError(errorMessage);

    populateTimingsForFailedCONNECT(harEntry);

    populateServerIpAddress(harEntry);


    return harEntry;
}
 
Example #11
Source File: QueryStringParameters.java    From bobcat with Apache License 2.0 4 votes vote down vote up
QueryStringParameters(HarRequest harRequest) {
  this.harRequest = harRequest;
}
 
Example #12
Source File: CaptureEntryViewHolder.java    From CapturePacket with MIT License 4 votes vote down vote up
void setData(HarEntry harEntry,int position,SimpleDateFormat format){
    mHarEntry = harEntry;
    if (mEntryTabDelegate != null && mEntryTabDelegate.mHarEntry == harEntry ) {
        onClick(mBarView);
    } else {
        setDefaultBackground();
    }

    HarRequest request = harEntry.getRequest();
    HarResponse response = harEntry.getResponse();
    setItemContent(HarEntryViewBar.TYPE_ID,String.valueOf(position));
    Date startedDateTime = harEntry.getStartedDateTime();
    if (startedDateTime != null) {
        setItemContent(HarEntryViewBar.TYPE_STARTED_TIME, format.format(startedDateTime));
    } else {
        setItemContent(HarEntryViewBar.TYPE_STARTED_TIME, "");
    }

    if (request != null) {
        setItemContent(HarEntryViewBar.TYPE_METHOD,request.getMethod());
        String url = request.getUrl();
        if (url != null) {
            Uri uri = Uri.parse(url);
            setItemContent(HarEntryViewBar.TYPE_HOST,uri.getHost());
            setItemContent(HarEntryViewBar.TYPE_PATH,uri.getPath());
        }else {
            setItemContent(HarEntryViewBar.TYPE_HOST,"");
            setItemContent(HarEntryViewBar.TYPE_PATH,"");
        }
    } else {
        setItemContent(HarEntryViewBar.TYPE_METHOD,"");
        setItemContent(HarEntryViewBar.TYPE_HOST,"");
        setItemContent(HarEntryViewBar.TYPE_PATH,"");
    }
    if (response != null) {
        setItemContent(HarEntryViewBar.TYPE_STATUS,String.valueOf(response.getStatus()));
        setItemContent(HarEntryViewBar.TYPE_TOTAL_SIZE,response.getBodySize()+ " bytes");
        setItemContent(HarEntryViewBar.TYPE_TOTAL_TIME,harEntry.getTime() + "ms");
    } else {
        setItemContent(HarEntryViewBar.TYPE_STATUS,"");
        setItemContent(HarEntryViewBar.TYPE_TOTAL_SIZE,"");
        setItemContent(HarEntryViewBar.TYPE_TOTAL_TIME,"");
    }
}
 
Example #13
Source File: HeadersTabHolder.java    From CapturePacket with MIT License 4 votes vote down vote up
@Override
public void onBindHolder(HarEntry harEntry,String tabText) {
    HarRequest request = harEntry.getRequest();
    HarResponse response = harEntry.getResponse();
    mAdapter.setHeaders(request == null ? null :request.getHeaders(),response == null ? null :response.getHeaders());
}
 
Example #14
Source File: HarCaptureFilter.java    From CapturePacket with MIT License 4 votes vote down vote up
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
    // if a ServerResponseCaptureFilter is configured, delegate to it to collect the client request. if it is not
    // configured, we still need to capture basic information (timings, possibly client headers, etc.), just not content.
    if (requestCaptureFilter != null) {
        requestCaptureFilter.clientToProxyRequest(httpObject);
    }

    if (httpObject instanceof HttpRequest) {
        // link the object up now, before we make the request, so that if we get cut off (ie: favicon.ico request and browser shuts down)
        // we still have the attempt associated, even if we never got a response
        harEntry.setStartedDateTime(new Date());
        har.getLog().addEntry(harEntry);

        HttpRequest httpRequest = (HttpRequest) httpObject;
        this.capturedOriginalRequest = httpRequest;

        // associate this request's HarRequest object with the har entry
        HarRequest request = createHarRequestForHttpRequest(httpRequest);
        harEntry.setRequest(request);

        // create a "no response received" HarResponse, in case the connection is interrupted, terminated, or the response is not received
        // for any other reason. having a "default" HarResponse prevents us from generating an invalid HAR.
        HarResponse defaultHarResponse = HarCaptureUtil.createHarResponseForFailure();
        defaultHarResponse.setError(HarCaptureUtil.getNoResponseReceivedErrorMessage());
        harEntry.setResponse(defaultHarResponse);

        captureQueryParameters(httpRequest);
        // not capturing user agent: in many cases, it doesn't make sense to capture at the HarLog level, since the proxy could be
        // serving requests from many different clients with various user agents. clients can turn on the REQUEST_HEADERS capture type
        // in order to capture the User-Agent header, if desired.
        captureRequestHeaderSize(httpRequest);

        if (dataToCapture.contains(CaptureType.REQUEST_COOKIES)) {
            captureRequestCookies(httpRequest);
        }

        if (dataToCapture.contains(CaptureType.REQUEST_HEADERS)) {
            captureRequestHeaders(httpRequest);
        }

        // The HTTP CONNECT to the proxy server establishes the SSL connection to the remote server, but the
        // HTTP CONNECT is not recorded in a separate HarEntry (except in case of error). Instead, the ssl and
        // connect times are recorded in the first request between the client and remote server after the HTTP CONNECT.
        captureConnectTiming();
    }

    if (httpObject instanceof HttpContent) {
        HttpContent httpContent = (HttpContent) httpObject;

        captureRequestSize(httpContent);
    }

    if (httpObject instanceof LastHttpContent) {
        LastHttpContent lastHttpContent = (LastHttpContent) httpObject;
        if (dataToCapture.contains(CaptureType.REQUEST_HEADERS)) {
            captureTrailingHeaders(lastHttpContent);
        }

        if (dataToCapture.contains(CaptureType.REQUEST_CONTENT)) {
            captureRequestContent(requestCaptureFilter.getHttpRequest(), requestCaptureFilter.getFullRequestContents());
        }

        harEntry.getRequest().setBodySize(requestBodySize.get());

    }

    return null;
}
 
Example #15
Source File: HttpConnectHarCaptureFilter.java    From Dream-Catcher with MIT License 2 votes vote down vote up
/**
 * Creates a new {@link HarRequest} object for this failed HTTP CONNECT. Does not populate fields within the request,
 * such as the error message.
 *
 * @param httpConnectRequest the HTTP CONNECT request that failed
 * @return a new HAR request object
 */
private HarRequest createRequestForFailedConnect(HttpRequest httpConnectRequest) {
    String url = getFullUrl(httpConnectRequest);

    return new HarRequest(httpConnectRequest.getMethod().toString(), url, httpConnectRequest.getProtocolVersion().text());
}
 
Example #16
Source File: HttpConnectHarCaptureFilter.java    From AndroidHttpCapture with MIT License 2 votes vote down vote up
/**
 * Creates a new {@link HarRequest} object for this failed HTTP CONNECT. Does not populate fields within the request,
 * such as the error message.
 *
 * @param httpConnectRequest the HTTP CONNECT request that failed
 * @return a new HAR request object
 */
private HarRequest createRequestForFailedConnect(HttpRequest httpConnectRequest) {
    String url = getFullUrl(httpConnectRequest);

    return new HarRequest(httpConnectRequest.getMethod().toString(), url, httpConnectRequest.getProtocolVersion().text());
}
 
Example #17
Source File: HttpConnectHarCaptureFilter.java    From CapturePacket with MIT License 2 votes vote down vote up
/**
 * Creates a new {@link HarRequest} object for this failed HTTP CONNECT. Does not populate fields within the request,
 * such as the error message.
 *
 * @param httpConnectRequest the HTTP CONNECT request that failed
 * @return a new HAR request object
 */
private HarRequest createRequestForFailedConnect(HttpRequest httpConnectRequest) {
    String url = getFullUrl(httpConnectRequest);

    return new HarRequest(httpConnectRequest.getMethod().toString(), url, httpConnectRequest.getProtocolVersion().text());
}