AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirect(true).build();
AsyncHttpClient c = getAsyncHttpClient(cg);
// If the test hit a proxy, no ConnectException will be thrown and instead of 404 will be returned.
try {
Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", String.format("http://127.0.0.1:%d/", port2)).execute().get();
assertNotNull(response);
assertEquals(response.getStatusCode(), 404);
} catch (ExecutionException ex) {
assertEquals(ex.getCause().getClass(), ConnectException.class);