@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(groups = "standalone")
 public void testQueryParameters() throws Exception {
   try (AsyncHttpClient client = asyncHttpClient()) {
     Future<Response> f =
         client
             .prepareGet("http://127.0.0.1:" + port1 + "/foo")
             .addHeader("Accepts", "*/*")
             .execute();
     Response resp = f.get(3, TimeUnit.SECONDS);
     assertNotNull(resp);
     assertEquals(resp.getStatusCode(), 400);
     assertEquals(resp.getResponseBody(), BAD_REQUEST_STR);
   }
 }
  @Test(groups = "online", enabled = false)
  public void testAHC62Com() throws Exception {
    try (AsyncHttpClient c = asyncHttpClient(config().setFollowRedirect(true))) {
      Response response =
          c.prepareGet("http://api.crunchbase.com/v/1/financial-organization/kinsey-hills-group.js")
              .execute(
                  new AsyncHandler<Response>() {

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

                    public void onThrowable(Throwable t) {
                      t.printStackTrace();
                    }

                    public State onBodyPartReceived(HttpResponseBodyPart bodyPart)
                        throws Exception {
                      System.out.println(bodyPart.getBodyPartBytes().length);
                      builder.accumulate(bodyPart);

                      return State.CONTINUE;
                    }

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

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

                    public Response onCompleted() throws Exception {
                      return builder.build();
                    }
                  })
              .get(10, TimeUnit.SECONDS);
      assertNotNull(response);
      assertTrue(response.getResponseBody().length() >= 3870);
    }
  }