@Test
  public void asyncStream302RedirectWithBody() throws Throwable {

    withClient(config().setFollowRedirect(true))
        .run(
            client -> {
              withServer(server)
                  .run(
                      server -> {
                        String originalUrl = server.getHttpUrl() + "/original";
                        String redirectUrl = server.getHttpUrl() + "/redirect";

                        server.enqueueResponse(
                            response -> {
                              response.setStatus(302);
                              response.setHeader(LOCATION.toString(), redirectUrl);
                              response
                                  .getOutputStream()
                                  .println("You are being asked to redirect to " + redirectUrl);
                            });
                        server.enqueueOk();

                        Response response =
                            client.prepareGet(originalUrl).execute().get(20, TimeUnit.SECONDS);

                        assertEquals(response.getStatusCode(), 200);
                        assertTrue(response.getResponseBody().isEmpty());
                      });
            });
  }
  @Test
  public void closeConnectionTest() throws Throwable {

    withClient()
        .run(
            client -> {
              withServer(server)
                  .run(
                      server -> {
                        server.enqueueEcho();

                        Response r =
                            client
                                .prepareGet(getTargetUrl())
                                .execute(
                                    new AsyncHandler<Response>() {

                                      private Response.ResponseBuilder builder =
                                          new Response.ResponseBuilder();

                                      public State onHeadersReceived(HttpResponseHeaders content)
                                          throws Exception {
                                        builder.accumulate(content);
                                        return State.CONTINUE;
                                      }

                                      public void onThrowable(Throwable t) {}

                                      public State onBodyPartReceived(HttpResponseBodyPart content)
                                          throws Exception {
                                        builder.accumulate(content);
                                        return content.isLast() ? State.ABORT : State.CONTINUE;
                                      }

                                      public State onStatusReceived(
                                          HttpResponseStatus responseStatus) throws Exception {
                                        builder.accumulate(responseStatus);

                                        return State.CONTINUE;
                                      }

                                      public Response onCompleted() throws Exception {
                                        return builder.build();
                                      }
                                    })
                                .get();

                        assertNotNull(r);
                        assertEquals(r.getStatusCode(), 200);
                      });
            });
  }