@Test public void captureRequest_https() throws Exception { ImmutableHttpResponse alwaysResponse = ImmutableHttpResponse.builder(201) .content(MediaType.PLAIN_TEXT_UTF_8, CharSource.wrap("not a real server").asByteSource(StandardCharsets.UTF_8)) .build(); BmpResponseManufacturer responseManufacturer = new BmpResponseManufacturer<Object>() { @Override public ResponseCapture manufacture(Object state, RequestCapture capture) { return ResponseCapture.matched(new BmpHttpAssistant().constructResponse(capture, alwaysResponse)); } @Override public Object createFreshState() { return new Object(); } }; BrowsermobVhsConfig vhsConfig = BrowsermobVhsConfig.builder(responseManufacturer) .tlsEndpointFactory(NanohttpdTlsEndpointFactory.create(BmpTests.generateKeystoreForUnitTest("localhost"), null)) .scratchDirProvider(ScratchDirProvider.under(temporaryFolder.getRoot().toPath())) .build(); List<RequestCapture> requests = Collections.synchronizedList(new ArrayList<>()); BrowsermobVirtualHarServer server = new BrowsermobVirtualHarServer(vhsConfig) { @Override ResponseManufacturingFiltersSource createFirstFiltersSource(BmpResponseManufacturer.WithState<?> responseManufacturer, HostRewriter hostRewriter, BmpResponseListener bmpResponseListener, ResponseManufacturingFiltersSource.PassthruPredicate passthruPredicate) { return new ResponseManufacturingFiltersSource(responseManufacturer, hostRewriter, bmpResponseListener, passthruPredicate) { @Override ResponseManufacturingFilter createResponseManufacturingFilter(HttpRequest originalRequest, ChannelHandlerContext ctx, BmpResponseManufacturer.WithState<?> responseManufacturer, BmpResponseListener bmpResponseListener) { return new ResponseManufacturingFilter(originalRequest, ctx, responseManufacturer, bmpResponseListener) { @Override RequestCapture freezeRequestCapture() { RequestCapture frozen = super.freezeRequestCapture(); requests.add(frozen); return frozen; } }; } }; } }; URI requestUri = URI.create("https: StatusLine responseStatus; try (VirtualHarServerControl ctrl = server.start()) { try (CloseableHttpClient client = VhsTests.buildBlindlyTrustingHttpClient(ctrl.getSocketAddress())) { HttpGet request = new HttpGet(requestUri); try (CloseableHttpResponse response = client.execute(request)) { responseStatus = response.getStatusLine(); } } } assertEquals("response status", alwaysResponse.status, responseStatus.getStatusCode()); assertEquals("num requests parsed", 1, requests.size()); ParsedRequest parsedRequest = requests.iterator().next().request; assertEquals("parsed request uri", requestUri, parsedRequest.url); }
@VisibleForTesting RequestCapture freezeRequestCapture() { return requestAccumulator.freeze(); }
ResponseManufacturingFilter extends HttpsAwareFiltersAdapter { @VisibleForTesting RequestCapture freezeRequestCapture() { return requestAccumulator.freeze(); } }
ResponseManufacturingFilter extends HttpsAwareFiltersAdapter { @VisibleForTesting RequestCapture freezeRequestCapture() { return requestAccumulator.freeze(); } <S> ResponseManufacturingFilter(HttpRequest originalRequest, ChannelHandlerContext ctx, BmpResponseManufacturer.WithState<S> responseManufacturer, BmpResponseListener responseListener); }
ResponseManufacturingFilter extends HttpsAwareFiltersAdapter { @VisibleForTesting RequestCapture freezeRequestCapture() { return requestAccumulator.freeze(); } <S> ResponseManufacturingFilter(HttpRequest originalRequest, ChannelHandlerContext ctx, BmpResponseManufacturer.WithState<S> responseManufacturer, BmpResponseListener responseListener); @Override HttpResponse clientToProxyRequest(HttpObject httpObject); @Override final HttpObject proxyToClientResponse(HttpObject httpObject); @Override HttpObject serverToProxyResponse(HttpObject httpObject); @Override void proxyToServerResolutionSucceeded(String serverHostAndPort, InetSocketAddress resolvedRemoteAddress); @Override void proxyToServerRequestSending(); @Override void proxyToServerResolutionFailed(String hostAndPort); @Override void proxyToServerConnectionFailed(); @Override void serverToProxyResponseTimedOut(); @Override HttpResponse proxyToServerRequest(HttpObject httpObject); @Override void proxyToServerRequestSent(); @Override void serverToProxyResponseReceiving(); @Override void serverToProxyResponseReceived(); @Override void proxyToServerConnectionQueued(); @Override InetSocketAddress proxyToServerResolutionStarted(String resolvingServerHostAndPort); @Override void proxyToServerConnectionStarted(); @Override void proxyToServerConnectionSSLHandshakeStarted(); @Override void proxyToServerConnectionSucceeded(ChannelHandlerContext serverCtx); }
ResponseManufacturingFilter extends HttpsAwareFiltersAdapter { @VisibleForTesting RequestCapture freezeRequestCapture() { return requestAccumulator.freeze(); } <S> ResponseManufacturingFilter(HttpRequest originalRequest, ChannelHandlerContext ctx, BmpResponseManufacturer.WithState<S> responseManufacturer, BmpResponseListener responseListener); @Override HttpResponse clientToProxyRequest(HttpObject httpObject); @Override final HttpObject proxyToClientResponse(HttpObject httpObject); @Override HttpObject serverToProxyResponse(HttpObject httpObject); @Override void proxyToServerResolutionSucceeded(String serverHostAndPort, InetSocketAddress resolvedRemoteAddress); @Override void proxyToServerRequestSending(); @Override void proxyToServerResolutionFailed(String hostAndPort); @Override void proxyToServerConnectionFailed(); @Override void serverToProxyResponseTimedOut(); @Override HttpResponse proxyToServerRequest(HttpObject httpObject); @Override void proxyToServerRequestSent(); @Override void serverToProxyResponseReceiving(); @Override void serverToProxyResponseReceived(); @Override void proxyToServerConnectionQueued(); @Override InetSocketAddress proxyToServerResolutionStarted(String resolvingServerHostAndPort); @Override void proxyToServerConnectionStarted(); @Override void proxyToServerConnectionSSLHandshakeStarted(); @Override void proxyToServerConnectionSucceeded(ChannelHandlerContext serverCtx);  }