@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 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 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); } } }
@Override public void proxyToServerResolutionSucceeded(String serverHostAndPort, InetSocketAddress resolvedRemoteAddress) { long dnsResolutionFinishedNanos = System.nanoTime(); if (dnsResolutionStartedNanos > 0L) { harEntry.getTimings().setDns(dnsResolutionFinishedNanos - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS); } else { harEntry.getTimings().setDns(0L, TimeUnit.NANOSECONDS); } // the address *should* always be resolved at this point InetAddress resolvedAddress = resolvedRemoteAddress.getAddress(); if (resolvedAddress != null) { addressResolved = true; harEntry.setServerIPAddress(resolvedAddress.getHostAddress()); } }
/** * Populates ssl and connect timing info in the HAR if an entry for this client and server exist in the cache. */ protected void captureConnectTiming() { HttpConnectTiming httpConnectTiming = HttpConnectHarCaptureFilter.consumeConnectTimingForConnection(clientAddress); if (httpConnectTiming != null) { harEntry.getTimings().setSsl(httpConnectTiming.getSslHandshakeTimeNanos(), TimeUnit.NANOSECONDS); harEntry.getTimings().setConnect(httpConnectTiming.getConnectTimeNanos(), TimeUnit.NANOSECONDS); harEntry.getTimings().setBlocked(httpConnectTiming.getBlockedTimeNanos(), TimeUnit.NANOSECONDS); harEntry.getTimings().setDns(httpConnectTiming.getDnsTimeNanos(), TimeUnit.NANOSECONDS); } }
@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); } }
@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); }
@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); } }
@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); } }
@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); } }
/** * Populates timing information in the specified harEntry for failed rquests. Populates as much timing information * as possible, up to the point of failure. * * @param harEntry HAR entry to populate timing information in */ private void populateTimingsForFailedCONNECT(HarEntry harEntry) { HarTimings timings = harEntry.getTimings(); if (connectionQueuedNanos > 0L && dnsResolutionStartedNanos > 0L) { timings.setBlocked(dnsResolutionStartedNanos - connectionQueuedNanos, TimeUnit.NANOSECONDS); } if (dnsResolutionStartedNanos > 0L && dnsResolutionFinishedNanos > 0L) { timings.setDns(dnsResolutionFinishedNanos - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS); } if (connectionStartedNanos > 0L && connectionSucceededTimeNanos > 0L) { timings.setConnect(connectionSucceededTimeNanos - connectionStartedNanos, TimeUnit.NANOSECONDS); if (sslHandshakeStartedNanos > 0L) { timings.setSsl(connectionSucceededTimeNanos - this.sslHandshakeStartedNanos, TimeUnit.NANOSECONDS); } } if (sendStartedNanos > 0L && sendFinishedNanos >= 0L) { timings.setSend(sendFinishedNanos - sendStartedNanos, TimeUnit.NANOSECONDS); } if (sendFinishedNanos > 0L && responseReceiveStartedNanos >= 0L) { timings.setWait(responseReceiveStartedNanos - sendFinishedNanos, TimeUnit.NANOSECONDS); } // since this method is for HTTP CONNECT failures only, we can't populate a "received" time, since that would // require the CONNECT to be successful, in which case this method wouldn't be called. }
HarTimings timings = getTimings(); if (timings == null) { return -1;
@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); } }
/** * Populates ssl and connect timing info in the HAR if an entry for this client and server exist in the cache. */ protected void captureConnectTiming() { HttpConnectTiming httpConnectTiming = HttpConnectHarCaptureFilter.consumeConnectTimingForConnection(clientAddress); if (httpConnectTiming != null) { harEntry.getTimings().setSsl(httpConnectTiming.getSslHandshakeTimeNanos(), TimeUnit.NANOSECONDS); harEntry.getTimings().setConnect(httpConnectTiming.getConnectTimeNanos(), TimeUnit.NANOSECONDS); harEntry.getTimings().setBlocked(httpConnectTiming.getBlockedTimeNanos(), TimeUnit.NANOSECONDS); harEntry.getTimings().setDns(httpConnectTiming.getDnsTimeNanos(), TimeUnit.NANOSECONDS); } }
@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); }
@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); } }