@Test public void acceptEncodingIsObeyed() throws Exception { io.github.mike10004.vhs.harbridge.Hars.class.getName(); ReplayManager replayManager = new VhsReplayManager(); Fixture fixture = fixturesRule.getFixtures().http(); File harFile = fixture.harFile(); ReplaySessionConfig config = ReplaySessionConfig.builder(temporaryFolder.getRoot().toPath()) .build(harFile); URI url = fixture.startUrl(); try (ReplaySessionControl ctrl = replayManager.start(config)) { HostAndPort proxyAddress = ctrl.getSocketAddress(); System.out.format("fetching %s%n", url); ImmutableHttpResponse rsp = Tests.fetchWithNoAcceptEncodingRequestHeader(proxyAddress, url); String actual = rsp.data.asCharSource(StandardCharsets.UTF_8).read(); boolean allAscii = ASCII.matchesAllOf(actual); if (!allAscii) { System.out.format("text \"%s\" has first non-ascii character at index %d%n", StringEscapeUtils.escapeJava(StringUtils.abbreviateMiddle(actual, "[...]", 64)), ASCII.negate().indexIn(actual)); } assertTrue("response content all ascii", allAscii); } }
@Override public ReplaySessionControl start(ReplaySessionConfig sessionConfig) throws IOException { EntryMatcher harEntryMatcher = buildHarEntryMatcher(sessionConfig); EntryMatcher compositeEntryMatcher = enhanceEntryMatcherFromConfig(harEntryMatcher, sessionConfig.replayServerConfig); List<ResponseInterceptor> interceptors = new ArrayList<>(); interceptors.addAll(buildInterceptorsForReplacements(sessionConfig.replayServerConfig.replacements)); interceptors.addAll(buildInterceptorsForTransforms(sessionConfig.replayServerConfig.responseHeaderTransforms)); int port = sessionConfig.port; VirtualHarServer vhs = createVirtualHarServer(port, sessionConfig.scratchDir, compositeEntryMatcher, interceptors, config.bmpResponseListener); VirtualHarServerControl ctrl = vhs.start(); Runnable stopListener = () -> { sessionConfig.serverTerminationCallbacks.forEach(c -> { c.terminated(null); }); }; return new VhsReplaySessionControl(ctrl, true, stopListener); }
VhsReplayManager implements ReplayManager { @Override public ReplaySessionControl start(ReplaySessionConfig sessionConfig) throws IOException { EntryMatcher harEntryMatcher = buildHarEntryMatcher(sessionConfig); EntryMatcher compositeEntryMatcher = enhanceEntryMatcherFromConfig(harEntryMatcher, sessionConfig.replayServerConfig); List<ResponseInterceptor> interceptors = new ArrayList<>(); interceptors.addAll(buildInterceptorsForReplacements(sessionConfig.replayServerConfig.replacements)); interceptors.addAll(buildInterceptorsForTransforms(sessionConfig.replayServerConfig.responseHeaderTransforms)); int port = sessionConfig.port; VirtualHarServer vhs = createVirtualHarServer(port, sessionConfig.scratchDir, compositeEntryMatcher, interceptors, config.bmpResponseListener); VirtualHarServerControl ctrl = vhs.start(); Runnable stopListener = () -> { sessionConfig.serverTerminationCallbacks.forEach(c -> { c.terminated(null); }); }; return new VhsReplaySessionControl(ctrl, true, stopListener); } }
VhsReplayManager implements ReplayManager { @Override public ReplaySessionControl start(ReplaySessionConfig sessionConfig) throws IOException { EntryMatcher harEntryMatcher = buildHarEntryMatcher(sessionConfig); EntryMatcher compositeEntryMatcher = enhanceEntryMatcherFromConfig(harEntryMatcher, sessionConfig.replayServerConfig); List<ResponseInterceptor> interceptors = new ArrayList<>(); interceptors.addAll(buildInterceptorsForReplacements(sessionConfig.replayServerConfig.replacements)); interceptors.addAll(buildInterceptorsForTransforms(sessionConfig.replayServerConfig.responseHeaderTransforms)); int port = sessionConfig.port; VirtualHarServer vhs = createVirtualHarServer(port, sessionConfig.scratchDir, compositeEntryMatcher, interceptors, config.bmpResponseListener); VirtualHarServerControl ctrl = vhs.start(); Runnable stopListener = () -> { sessionConfig.serverTerminationCallbacks.forEach(c -> { c.terminated(null); }); }; return new VhsReplaySessionControl(ctrl, true, stopListener); } VhsReplayManager();  VhsReplayManager(VhsReplayManagerConfig config); protected  VhsReplayManager(VhsReplayManagerConfig config, EntryMatcherFactory entryMatcherFactory); }
VhsReplayManager implements ReplayManager { @Override public ReplaySessionControl start(ReplaySessionConfig sessionConfig) throws IOException { EntryMatcher harEntryMatcher = buildHarEntryMatcher(sessionConfig); EntryMatcher compositeEntryMatcher = enhanceEntryMatcherFromConfig(harEntryMatcher, sessionConfig.replayServerConfig); List<ResponseInterceptor> interceptors = new ArrayList<>(); interceptors.addAll(buildInterceptorsForReplacements(sessionConfig.replayServerConfig.replacements)); interceptors.addAll(buildInterceptorsForTransforms(sessionConfig.replayServerConfig.responseHeaderTransforms)); int port = sessionConfig.port; VirtualHarServer vhs = createVirtualHarServer(port, sessionConfig.scratchDir, compositeEntryMatcher, interceptors, config.bmpResponseListener); VirtualHarServerControl ctrl = vhs.start(); Runnable stopListener = () -> { sessionConfig.serverTerminationCallbacks.forEach(c -> { c.terminated(null); }); }; return new VhsReplaySessionControl(ctrl, true, stopListener); } VhsReplayManager();  VhsReplayManager(VhsReplayManagerConfig config); protected  VhsReplayManager(VhsReplayManagerConfig config, EntryMatcherFactory entryMatcherFactory); @Override ReplaySessionControl start(ReplaySessionConfig sessionConfig); }
VhsReplayManager implements ReplayManager { @Override public ReplaySessionControl start(ReplaySessionConfig sessionConfig) throws IOException { EntryMatcher harEntryMatcher = buildHarEntryMatcher(sessionConfig); EntryMatcher compositeEntryMatcher = enhanceEntryMatcherFromConfig(harEntryMatcher, sessionConfig.replayServerConfig); List<ResponseInterceptor> interceptors = new ArrayList<>(); interceptors.addAll(buildInterceptorsForReplacements(sessionConfig.replayServerConfig.replacements)); interceptors.addAll(buildInterceptorsForTransforms(sessionConfig.replayServerConfig.responseHeaderTransforms)); int port = sessionConfig.port; VirtualHarServer vhs = createVirtualHarServer(port, sessionConfig.scratchDir, compositeEntryMatcher, interceptors, config.bmpResponseListener); VirtualHarServerControl ctrl = vhs.start(); Runnable stopListener = () -> { sessionConfig.serverTerminationCallbacks.forEach(c -> { c.terminated(null); }); }; return new VhsReplaySessionControl(ctrl, true, stopListener); } VhsReplayManager();  VhsReplayManager(VhsReplayManagerConfig config); protected  VhsReplayManager(VhsReplayManagerConfig config, EntryMatcherFactory entryMatcherFactory); @Override ReplaySessionControl start(ReplaySessionConfig sessionConfig);  }