HttpGet get = new HttpGet("http://localhost:" + portNum + "/users/homer");
// do not follow redirects
RequestConfig requestconfig = RequestConfig.custom().setRedirectsEnabled(false).build();
CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestconfig).build();
try {
HttpResponse response = client.execute(get);
for (Header header : response.getAllHeaders()) {
log.info("Header {}", header);
}
assertEquals(302, response.getStatusLine().getStatusCode());
assertTrue("Should have location header", response.containsHeader("Location"));
assertEquals("http://somewhere.com", response.getFirstHeader("Location").getValue());
assertEquals("bar", response.getFirstHeader("Foo").getValue());
} finally {
client.close();
}
}