net.lightbody.bmp.filters.util.HarCaptureUtil Java Examples

The following examples show how to use net.lightbody.bmp.filters.util.HarCaptureUtil. 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: HttpConnectHarCaptureFilter.java    From CapturePacket with MIT License 6 votes vote down vote up
@Override
public void serverToProxyResponseTimedOut() {
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getResponseTimedOutErrorMessage());
    har.getLog().addEntry(harEntry);

    // include this timeout time in the HarTimings object
    long timeoutTimestampNanos = System.nanoTime();

    // if the proxy started to send the request but has not yet finished, we are currently "sending"
    if (sendStartedNanos > 0L && sendFinishedNanos == 0L) {
        harEntry.getTimings().setSend(timeoutTimestampNanos - sendStartedNanos, TimeUnit.NANOSECONDS);
    }
    // if the entire request was sent but the proxy has not begun receiving the response, we are currently "waiting"
    else if (sendFinishedNanos > 0L && responseReceiveStartedNanos == 0L) {
        harEntry.getTimings().setWait(timeoutTimestampNanos - sendFinishedNanos, TimeUnit.NANOSECONDS);
    }
    // if the proxy has already begun to receive the response, we are currenting "receiving"
    else if (responseReceiveStartedNanos > 0L) {
        harEntry.getTimings().setReceive(timeoutTimestampNanos - responseReceiveStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #2
Source File: HarCaptureFilter.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
@Override
public void serverToProxyResponseTimedOut() {
    // replace any existing HarResponse that was created if the server sent a partial response
    HarResponse response = HarCaptureUtil.createHarResponseForFailure();
    harEntry.setResponse(response);

    response.setError(HarCaptureUtil.getResponseTimedOutErrorMessage());


    // include this timeout time in the HarTimings object
    long timeoutTimestampNanos = System.nanoTime();

    // if the proxy started to send the request but has not yet finished, we are currently "sending"
    if (sendStartedNanos > 0L && sendFinishedNanos == 0L) {
        harEntry.getTimings().setSend(timeoutTimestampNanos - sendStartedNanos, TimeUnit.NANOSECONDS);
    }
    // if the entire request was sent but the proxy has not begun receiving the response, we are currently "waiting"
    else if (sendFinishedNanos > 0L && responseReceiveStartedNanos == 0L) {
        harEntry.getTimings().setWait(timeoutTimestampNanos - sendFinishedNanos, TimeUnit.NANOSECONDS);
    }
    // if the proxy has already begun to receive the response, we are currenting "receiving"
    else if (responseReceiveStartedNanos > 0L) {
        harEntry.getTimings().setReceive(timeoutTimestampNanos - responseReceiveStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #3
Source File: HarCaptureFilter.java    From CapturePacket with MIT License 6 votes vote down vote up
@Override
public void serverToProxyResponseTimedOut() {
    // replace any existing HarResponse that was created if the server sent a partial response
    HarResponse response = HarCaptureUtil.createHarResponseForFailure();
    harEntry.setResponse(response);

    response.setError(HarCaptureUtil.getResponseTimedOutErrorMessage());


    // include this timeout time in the HarTimings object
    long timeoutTimestampNanos = System.nanoTime();

    // if the proxy started to send the request but has not yet finished, we are currently "sending"
    if (sendStartedNanos > 0L && sendFinishedNanos == 0L) {
        harEntry.getTimings().setSend(timeoutTimestampNanos - sendStartedNanos, TimeUnit.NANOSECONDS);
    }
    // if the entire request was sent but the proxy has not begun receiving the response, we are currently "waiting"
    else if (sendFinishedNanos > 0L && responseReceiveStartedNanos == 0L) {
        harEntry.getTimings().setWait(timeoutTimestampNanos - sendFinishedNanos, TimeUnit.NANOSECONDS);
    }
    // if the proxy has already begun to receive the response, we are currenting "receiving"
    else if (responseReceiveStartedNanos > 0L) {
        harEntry.getTimings().setReceive(timeoutTimestampNanos - responseReceiveStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #4
Source File: HttpConnectHarCaptureFilter.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
@Override
public void serverToProxyResponseTimedOut() {
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getResponseTimedOutErrorMessage());
    har.getLog().addEntry(harEntry);

    // include this timeout time in the HarTimings object
    long timeoutTimestampNanos = System.nanoTime();

    // if the proxy started to send the request but has not yet finished, we are currently "sending"
    if (sendStartedNanos > 0L && sendFinishedNanos == 0L) {
        harEntry.getTimings().setSend(timeoutTimestampNanos - sendStartedNanos, TimeUnit.NANOSECONDS);
    }
    // if the entire request was sent but the proxy has not begun receiving the response, we are currently "waiting"
    else if (sendFinishedNanos > 0L && responseReceiveStartedNanos == 0L) {
        harEntry.getTimings().setWait(timeoutTimestampNanos - sendFinishedNanos, TimeUnit.NANOSECONDS);
    }
    // if the proxy has already begun to receive the response, we are currenting "receiving"
    else if (responseReceiveStartedNanos > 0L) {
        harEntry.getTimings().setReceive(timeoutTimestampNanos - responseReceiveStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #5
Source File: HttpConnectHarCaptureFilter.java    From Dream-Catcher with MIT License 6 votes vote down vote up
@Override
public void serverToProxyResponseTimedOut() {
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getResponseTimedOutErrorMessage());
    har.getLog().addEntry(harEntry);

    // include this timeout time in the HarTimings object
    long timeoutTimestampNanos = System.nanoTime();

    // if the proxy started to send the request but has not yet finished, we are currently "sending"
    if (sendStartedNanos > 0L && sendFinishedNanos == 0L) {
        harEntry.getTimings().setSend(timeoutTimestampNanos - sendStartedNanos, TimeUnit.NANOSECONDS);
    }
    // if the entire request was sent but the proxy has not begun receiving the response, we are currently "waiting"
    else if (sendFinishedNanos > 0L && responseReceiveStartedNanos == 0L) {
        harEntry.getTimings().setWait(timeoutTimestampNanos - sendFinishedNanos, TimeUnit.NANOSECONDS);
    }
    // if the proxy has already begun to receive the response, we are currenting "receiving"
    else if (responseReceiveStartedNanos > 0L) {
        harEntry.getTimings().setReceive(timeoutTimestampNanos - responseReceiveStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #6
Source File: HttpConnectHarCaptureFilter.java    From CapturePacket with MIT License 5 votes vote down vote up
@Override
public void proxyToServerConnectionFailed() {
    // since this is a CONNECT, which is not handled by the HarCaptureFilter, we need to create and populate the
    // entire HarEntry and add it to this har.
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getConnectionFailedErrorMessage());
    har.getLog().addEntry(harEntry);

    // record the amount of time we attempted to connect in the HarTimings object
    if (connectionStartedNanos > 0L) {
        harEntry.getTimings().setConnect(System.nanoTime() - connectionStartedNanos, TimeUnit.NANOSECONDS);
    }

    httpConnectTimes.remove(clientAddress);
}
 
Example #7
Source File: HarCaptureFilter.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
@Override
public void proxyToServerConnectionFailed() {
    HarResponse response = HarCaptureUtil.createHarResponseForFailure();
    harEntry.setResponse(response);

    response.setError(HarCaptureUtil.getConnectionFailedErrorMessage());

    // record the amount of time we attempted to connect in the HarTimings object
    if (connectionStartedNanos > 0L) {
        harEntry.getTimings().setConnect(System.nanoTime() - connectionStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #8
Source File: HarCaptureFilter.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
@Override
public void proxyToServerResolutionFailed(String hostAndPort) {
    HarResponse response = HarCaptureUtil.createHarResponseForFailure();
    harEntry.setResponse(response);

    response.setError(HarCaptureUtil.getResolutionFailedErrorMessage(hostAndPort));

    // record the amount of time we attempted to resolve the hostname in the HarTimings object
    if (dnsResolutionStartedNanos > 0L) {
        harEntry.getTimings().setDns(System.nanoTime() - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #9
Source File: HttpConnectHarCaptureFilter.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
@Override
public void proxyToServerConnectionFailed() {
    // since this is a CONNECT, which is not handled by the HarCaptureFilter, we need to create and populate the
    // entire HarEntry and add it to this har.
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getConnectionFailedErrorMessage());
    har.getLog().addEntry(harEntry);

    // record the amount of time we attempted to connect in the HarTimings object
    if (connectionStartedNanos > 0L) {
        harEntry.getTimings().setConnect(System.nanoTime() - connectionStartedNanos, TimeUnit.NANOSECONDS);
    }

    httpConnectTimes.remove(clientAddress);
}
 
Example #10
Source File: HttpConnectHarCaptureFilter.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
@Override
public void proxyToServerResolutionFailed(String hostAndPort) {
    // since this is a CONNECT, which is not handled by the HarCaptureFilter, we need to create and populate the
    // entire HarEntry and add it to this har.
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getResolutionFailedErrorMessage(hostAndPort));
    har.getLog().addEntry(harEntry);

    // record the amount of time we attempted to resolve the hostname in the HarTimings object
    if (dnsResolutionStartedNanos > 0L) {
        harEntry.getTimings().setDns(System.nanoTime() - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS);
    }

    httpConnectTimes.remove(clientAddress);
}
 
Example #11
Source File: HarCaptureFilter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void proxyToServerConnectionFailed() {
    Log.e("Capture", "proxyToServerConnectionFailed " + harEntry.getId());
    HarResponse response = HarCaptureUtil.createHarResponseForFailure();
    harEntry.setResponse(response);

    response.setError(HarCaptureUtil.getConnectionFailedErrorMessage());

    // record the amount of time we attempted to connect in the HarTimings object
    if (connectionStartedNanos > 0L) {
        harEntry.getTimings().setConnect(System.nanoTime() - connectionStartedNanos, TimeUnit.NANOSECONDS);
    }
    proxyManager.httpExchangeFailed(response.getError());
}
 
Example #12
Source File: HarCaptureFilter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void proxyToServerResolutionFailed(String hostAndPort) {
    Log.e("Capture", "proxyToServerResolutionFailed " + harEntry.getId());
    HarResponse response = HarCaptureUtil.createHarResponseForFailure();
    harEntry.setResponse(response);

    response.setError(HarCaptureUtil.getResolutionFailedErrorMessage(hostAndPort));

    // record the amount of time we attempted to resolve the hostname in the HarTimings object
    if (dnsResolutionStartedNanos > 0L) {
        harEntry.getTimings().setDns(System.nanoTime() - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #13
Source File: HarCaptureFilter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void serverToProxyResponseTimedOut() {
    // replace any existing DCResponse that was created if the server sent a partial response
    Log.e("Capture", "serverToProxyResponseTimedOut " + harEntry.getId());
    HarResponse response = HarCaptureUtil.createHarResponseForFailure();
    harEntry.setResponse(response);

    response.setError(HarCaptureUtil.getResponseTimedOutErrorMessage());
    proxyManager.httpExchangeFailed(response.getError());


    // include this timeout time in the HarTimings object
    long timeoutTimestampNanos = System.nanoTime();

    // if the proxy started to send the request but has not yet finished, we are currently "sending"
    if (sendStartedNanos > 0L && sendFinishedNanos == 0L) {
        harEntry.getTimings().setSend(timeoutTimestampNanos - sendStartedNanos, TimeUnit.NANOSECONDS);
    }
    // if the entire request was sent but the proxy has not begun receiving the response, we are currently "waiting"
    else if (sendFinishedNanos > 0L && responseReceiveStartedNanos == 0L) {
        harEntry.getTimings().setWait(timeoutTimestampNanos - sendFinishedNanos, TimeUnit.NANOSECONDS);
    }
    // if the proxy has already begun to receive the response, we are currenting "receiving"
    else if (responseReceiveStartedNanos > 0L) {
        harEntry.getTimings().setReceive(timeoutTimestampNanos - responseReceiveStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #14
Source File: HttpConnectHarCaptureFilter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void proxyToServerConnectionFailed() {
    // since this is a CONNECT, which is not handled by the HarCaptureFilter, we need to create and populate the
    // entire HarEntry and add it to this har.
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getConnectionFailedErrorMessage());
    har.getLog().addEntry(harEntry);

    // record the amount of time we attempted to connect in the HarTimings object
    if (connectionStartedNanos > 0L) {
        harEntry.getTimings().setConnect(System.nanoTime() - connectionStartedNanos, TimeUnit.NANOSECONDS);
    }

    httpConnectTimes.remove(clientAddress);
}
 
Example #15
Source File: HttpConnectHarCaptureFilter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void proxyToServerResolutionFailed(String hostAndPort) {
    // since this is a CONNECT, which is not handled by the HarCaptureFilter, we need to create and populate the
    // entire HarEntry and add it to this har.
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getResolutionFailedErrorMessage(hostAndPort));
    har.getLog().addEntry(harEntry);

    // record the amount of time we attempted to resolve the hostname in the HarTimings object
    if (dnsResolutionStartedNanos > 0L) {
        harEntry.getTimings().setDns(System.nanoTime() - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS);
    }

    httpConnectTimes.remove(clientAddress);
}
 
Example #16
Source File: HarCaptureFilter.java    From CapturePacket with MIT License 5 votes vote down vote up
@Override
public void proxyToServerConnectionFailed() {
    HarResponse response = HarCaptureUtil.createHarResponseForFailure();
    harEntry.setResponse(response);

    response.setError(HarCaptureUtil.getConnectionFailedErrorMessage());

    // record the amount of time we attempted to connect in the HarTimings object
    if (connectionStartedNanos > 0L) {
        harEntry.getTimings().setConnect(System.nanoTime() - connectionStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #17
Source File: HarCaptureFilter.java    From CapturePacket with MIT License 5 votes vote down vote up
@Override
public void proxyToServerResolutionFailed(String hostAndPort) {
    HarResponse response = HarCaptureUtil.createHarResponseForFailure();
    harEntry.setResponse(response);

    response.setError(HarCaptureUtil.getResolutionFailedErrorMessage(hostAndPort));

    // record the amount of time we attempted to resolve the hostname in the HarTimings object
    if (dnsResolutionStartedNanos > 0L) {
        harEntry.getTimings().setDns(System.nanoTime() - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #18
Source File: HttpConnectHarCaptureFilter.java    From CapturePacket with MIT License 5 votes vote down vote up
@Override
public void proxyToServerResolutionFailed(String hostAndPort) {
    // since this is a CONNECT, which is not handled by the HarCaptureFilter, we need to create and populate the
    // entire HarEntry and add it to this har.
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getResolutionFailedErrorMessage(hostAndPort));
    har.getLog().addEntry(harEntry);

    // record the amount of time we attempted to resolve the hostname in the HarTimings object
    if (dnsResolutionStartedNanos > 0L) {
        harEntry.getTimings().setDns(System.nanoTime() - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS);
    }

    httpConnectTimes.remove(clientAddress);
}
 
Example #19
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 #20
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 #21
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 #22
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 #23
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 #24
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;
}