@Test(groups = { "standalone", "default_provider" })
public void testMultipleOtherHeaders() throws IOException, ExecutionException, TimeoutException, InterruptedException {
final String[] xffHeaders = new String[] { null, null };
AsyncHttpClient ahc = getAsyncHttpClient(null);
try {
Request req = new RequestBuilder("GET").setUrl("http://localhost:" + port1 + "/MultiOther").build();
final CountDownLatch latch = new CountDownLatch(1);
ahc.executeRequest(req, new AsyncHandler<Void>() {
public void onThrowable(Throwable t) {
t.printStackTrace(System.out);
}
public STATE onBodyPartReceived(HttpResponseBodyPart objectHttpResponseBodyPart) throws Exception {
return STATE.CONTINUE;
}
public STATE onStatusReceived(HttpResponseStatus objectHttpResponseStatus) throws Exception {
return STATE.CONTINUE;
}
public STATE onHeadersReceived(HttpResponseHeaders response) throws Exception {
int i = 0;
for (String header : response.getHeaders().get("X-Forwarded-For")) {
xffHeaders[i++] = header;
}
latch.countDown();
return STATE.CONTINUE;
}
public Void onCompleted() throws Exception {
return null;
}
}).get(3, TimeUnit.SECONDS);
if (!latch.await(2, TimeUnit.SECONDS)) {
fail("Time out");
}
assertNotNull(xffHeaders[0]);
assertNotNull(xffHeaders[1]);
try {
assertEquals(xffHeaders[0], "abc");
assertEquals(xffHeaders[1], "def");
} catch (AssertionError ex) {
assertEquals(xffHeaders[1], "abc");
assertEquals(xffHeaders[0], "def");
}
} finally {
ahc.close();
}
}