@Test
  public void testMitmDisabledHttpsRequestFilterNotAvailable() throws IOException {
    mockServer
        .when(request().withMethod("GET").withPath("/mitmdisabled"), Times.exactly(1))
        .respond(response().withStatusCode(200).withBody("success"));

    proxy = new BrowserMobProxyServer();
    proxy.setMitmDisabled(true);

    proxy.start();

    final AtomicBoolean connectRequestFilterFired = new AtomicBoolean(false);
    final AtomicBoolean getRequestFilterFired = new AtomicBoolean(false);

    proxy.addRequestFilter(
        new RequestFilter() {
          @Override
          public HttpResponse filterRequest(
              HttpRequest request, HttpMessageContents contents, HttpMessageInfo messageInfo) {
            if (request.getMethod().equals(HttpMethod.CONNECT)) {
              connectRequestFilterFired.set(true);
            } else if (request.getMethod().equals(HttpMethod.GET)) {
              getRequestFilterFired.set(true);
            }
            return null;
          }
        });

    try (CloseableHttpClient httpClient =
        NewProxyServerTestUtil.getNewHttpClient(proxy.getPort())) {
      CloseableHttpResponse response =
          httpClient.execute(new HttpGet("https://localhost:" + mockServerPort + "/mitmdisabled"));

      assertEquals(
          "Expected server to return a 200", 200, response.getStatusLine().getStatusCode());

      assertTrue("Expected request filter to fire on CONNECT", connectRequestFilterFired.get());
      assertFalse(
          "Expected request filter to fail to fire on GET because MITM is disabled",
          getRequestFilterFired.get());
    }
  }
  @Test
  public void testMitmDisabledHttpsResponseFilterNotAvailable() throws IOException {
    mockServer
        .when(request().withMethod("GET").withPath("/mitmdisabled"), Times.exactly(1))
        .respond(response().withStatusCode(200).withBody("success"));

    proxy = new BrowserMobProxyServer();
    proxy.setMitmDisabled(true);

    proxy.start();

    // unlike the request filter, the response filter doesn't fire when the 200 response to the
    // CONNECT is sent to the client.
    // this is because the response filter is triggered when the serverToProxyResponse() filtering
    // method is called, and
    // the "200 Connection established" is generated by the proxy itself.

    final AtomicBoolean responseFilterFired = new AtomicBoolean(false);

    proxy.addResponseFilter(
        new ResponseFilter() {
          @Override
          public void filterResponse(
              HttpResponse response, HttpMessageContents contents, HttpMessageInfo messageInfo) {
            responseFilterFired.set(true);
          }
        });

    try (CloseableHttpClient httpClient =
        NewProxyServerTestUtil.getNewHttpClient(proxy.getPort())) {
      CloseableHttpResponse response =
          httpClient.execute(new HttpGet("https://localhost:" + mockServerPort + "/mitmdisabled"));

      assertEquals(
          "Expected server to return a 200", 200, response.getStatusLine().getStatusCode());
      assertFalse(
          "Expected response filter to fail to fire because MITM is disabled",
          responseFilterFired.get());
    }
  }