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

The following examples show how to use net.lightbody.bmp.core.har.HarResponse. 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: 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 #2
Source File: HarCaptureFilter.java    From CapturePacket with MIT License 6 votes vote down vote up
protected void captureResponse(HttpResponse httpResponse) {
    HarResponse response = new HarResponse(httpResponse.getStatus().code(), httpResponse.getStatus().reasonPhrase(), httpResponse.getProtocolVersion().text());
    harEntry.setResponse(response);

    captureResponseHeaderSize(httpResponse);

    captureResponseMimeType(httpResponse);

    if (dataToCapture.contains(CaptureType.RESPONSE_COOKIES)) {
        captureResponseCookies(httpResponse);
    }

    if (dataToCapture.contains(CaptureType.RESPONSE_HEADERS)) {
        captureResponseHeaders(httpResponse);
    }

    if (BrowserMobHttpUtil.isRedirect(httpResponse)) {
        captureRedirectUrl(httpResponse);
    }
}
 
Example #3
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 #4
Source File: HarCaptureFilter.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
protected void captureResponse(HttpResponse httpResponse) {
    HarResponse response = new HarResponse(httpResponse.getStatus().code(), httpResponse.getStatus().reasonPhrase(), httpResponse.getProtocolVersion().text());
    harEntry.setResponse(response);

    captureResponseHeaderSize(httpResponse);

    captureResponseMimeType(httpResponse);

    if (dataToCapture.contains(CaptureType.RESPONSE_COOKIES)) {
        captureResponseCookies(httpResponse);
    }

    if (dataToCapture.contains(CaptureType.RESPONSE_HEADERS)) {
        captureResponseHeaders(httpResponse);
    }

    if (BrowserMobHttpUtil.isRedirect(httpResponse)) {
        captureRedirectUrl(httpResponse);
    }
}
 
Example #5
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 #6
Source File: HarCaptureFilter.java    From Dream-Catcher with MIT License 6 votes vote down vote up
protected void captureResponse(HttpResponse httpResponse) {
    Log.e("InnerHandle", "captureResponse " + harEntry.getId());
    HarResponse response = new HarResponse(httpResponse.getStatus().code(), httpResponse.getStatus().reasonPhrase(), httpResponse.getProtocolVersion().text());
    harEntry.setResponse(response);

    captureResponseHeaderSize(httpResponse);

    captureResponseMimeType(httpResponse);

    if (dataToCapture.contains(CaptureType.RESPONSE_COOKIES)) {
        captureResponseCookies(httpResponse);
    }

    if (dataToCapture.contains(CaptureType.RESPONSE_HEADERS)) {
        captureResponseHeaders(httpResponse);
    }

    if (BrowserMobHttpUtil.isRedirect(httpResponse)) {
        captureRedirectUrl(httpResponse);
    }
}
 
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 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 #9
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 #10
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 #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 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 #13
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 #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: 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 #16
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 #17
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 #18
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 #19
Source File: DCResponse.java    From Dream-Catcher with MIT License 4 votes vote down vote up
public HarResponse getResponse() {
    return harEntry.getResponse();
}
 
Example #20
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 #21
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 #22
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 #23
Source File: HarCaptureUtil.java    From Dream-Catcher with MIT License 2 votes vote down vote up
/**
 * Creates a DCResponse object for failed requests. Normally the DCResponse is populated when the response is received
 * from the server, but if the request fails due to a name resolution issue, connection problem, timeout, etc., no
 * DCResponse would otherwise be created.
 *
 * @return a new DCResponse object with invalid HTTP status code (0) and version string ("unknown")
 */
public static HarResponse createHarResponseForFailure() {
    return new HarResponse(HTTP_STATUS_CODE_FOR_FAILURE, HTTP_REASON_PHRASE_FOR_FAILURE, HTTP_VERSION_STRING_FOR_FAILURE);
}
 
Example #24
Source File: HarCaptureUtil.java    From CapturePacket with MIT License 2 votes vote down vote up
/**
 * Creates a HarResponse object for failed requests. Normally the HarResponse is populated when the response is received
 * from the server, but if the request fails due to a name resolution issue, connection problem, timeout, etc., no
 * HarResponse would otherwise be created.
 *
 * @return a new HarResponse object with invalid HTTP status code (0) and version string ("unknown")
 */
public static HarResponse createHarResponseForFailure() {
    return new HarResponse(HTTP_STATUS_CODE_FOR_FAILURE, HTTP_REASON_PHRASE_FOR_FAILURE, HTTP_VERSION_STRING_FOR_FAILURE);
}
 
Example #25
Source File: HarCaptureUtil.java    From AndroidHttpCapture with MIT License 2 votes vote down vote up
/**
 * Creates a HarResponse object for failed requests. Normally the HarResponse is populated when the response is received
 * from the server, but if the request fails due to a name resolution issue, connection problem, timeout, etc., no
 * HarResponse would otherwise be created.
 *
 * @return a new HarResponse object with invalid HTTP status code (0) and version string ("unknown")
 */
public static HarResponse createHarResponseForFailure() {
    return new HarResponse(HTTP_STATUS_CODE_FOR_FAILURE, HTTP_REASON_PHRASE_FOR_FAILURE, HTTP_VERSION_STRING_FOR_FAILURE);
}