public PageRefFilteredHarLog(HarLog log, Set<String> pageRef) { super(); setBrowser(log.getBrowser()); setPages(getFilteredPages(log.getPages(), pageRef)); setEntries(getFilteredEntries(log.getEntries(), pageRef)); setComment(log.getComment()); }
public PageRefFilteredHar(Har har, String pageRef) { super(new PageRefFilteredHarLog(har.getLog(), pageRef)); } }
/** * 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); }
@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); }
@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); }
protected void captureResponseMimeType(HttpResponse httpResponse) { String contentType = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.CONTENT_TYPE); // don't set the mimeType to null, since mimeType is a required field if (contentType != null) { harEntry.getResponse().getContent().setMimeType(contentType); } }
@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); } }
@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); } }
protected void captureRedirectUrl(HttpResponse httpResponse) { String locationHeaderValue = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.LOCATION); if (locationHeaderValue != null) { harEntry.getResponse().setRedirectURL(locationHeaderValue); } }
@Override public InetSocketAddress proxyToServerResolutionStarted(String resolvingServerHostAndPort) { dnsResolutionStartedNanos = System.nanoTime(); // resolution started means the connection is no longer queued, so populate 'blocked' time if (connectionQueuedNanos > 0L) { harEntry.getTimings().setBlocked(dnsResolutionStartedNanos - connectionQueuedNanos, TimeUnit.NANOSECONDS); } else { harEntry.getTimings().setBlocked(0L, TimeUnit.NANOSECONDS); } return null; }
@Override public void proxyToServerRequestSent() { this.sendFinishedNanos = System.nanoTime(); // make sure the previous timestamp was captured, to avoid setting an absurd value in the har (see serverToProxyResponseReceiving()) if (sendStartedNanos > 0L) { harEntry.getTimings().setSend(sendFinishedNanos - sendStartedNanos, TimeUnit.NANOSECONDS); } else { harEntry.getTimings().setSend(0L, TimeUnit.NANOSECONDS); } }
@Override public void serverToProxyResponseReceiving() { this.responseReceiveStartedNanos = System.nanoTime(); // started to receive response, so populate the 'wait' time. if we started receiving a response from the server before we finished // sending (for example, the server replied with a 404 while we were uploading a large file), there was no wait time, so // make sure the wait is set to 0. if (sendFinishedNanos > 0L && sendFinishedNanos < responseReceiveStartedNanos) { harEntry.getTimings().setWait(responseReceiveStartedNanos - sendFinishedNanos, TimeUnit.NANOSECONDS); } else { harEntry.getTimings().setWait(0L, TimeUnit.NANOSECONDS); } }
@Override public void proxyToServerConnectionSucceeded(ChannelHandlerContext serverCtx) { long connectionSucceededTimeNanos = System.nanoTime(); // make sure the previous timestamp was captured, to avoid setting an absurd value in the har (see serverToProxyResponseReceiving()) if (connectionStartedNanos > 0L) { harEntry.getTimings().setConnect(connectionSucceededTimeNanos - connectionStartedNanos, TimeUnit.NANOSECONDS); } else { harEntry.getTimings().setConnect(0L, TimeUnit.NANOSECONDS); } }
@Override public void serverToProxyResponseReceived() { long responseReceivedNanos = System.nanoTime(); // like the wait time, the receive time requires that the serverToProxyResponseReceiving() method be called before this method is invoked. // typically that should happen, but it has been reported (https://github.com/lightbody/browsermob-proxy/issues/288) that it // sometimes does not. therefore, to be safe, make sure responseReceiveStartedNanos is populated before setting the receive time. if (responseReceiveStartedNanos > 0L) { harEntry.getTimings().setReceive(responseReceivedNanos - responseReceiveStartedNanos, TimeUnit.NANOSECONDS); } else { harEntry.getTimings().setReceive(0L, TimeUnit.NANOSECONDS); } } }
public void setSsl(long ssl) { setSsl(ssl, TimeUnit.MILLISECONDS); }
public long getSend() { return getSend(TimeUnit.MILLISECONDS); }
public Long getBlocked() { return getBlocked(TimeUnit.MILLISECONDS); }
public Long getDns() { return getDns(TimeUnit.MILLISECONDS); }
public PageRefFilteredHarLog(HarLog log, String pageRef) { super(); setBrowser(log.getBrowser()); setPages(getFilteredPages(log.getPages(), pageRef)); setEntries(getFilteredEntries(log.getEntries(), pageRef)); setComment(log.getComment()); }
public PageRefFilteredHar(Har har, Set<String> pageRef) { super(new PageRefFilteredHarLog(har.getLog(), pageRef)); }