use of testutils.TestHttpClient in project runwar by cfmlprojects.
the class ProxyPeerAddressTest method testForwardFor.
@Test
public void testForwardFor() throws IOException {
String port = "8088";
String forwardFor = "some.domain.forwarded";
assertTrue(DefaultServer.getServerOptions().isProxyPeerAddressEnabled());
final TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/dumprunwarrequest");
get.addHeader(Headers.X_FORWARDED_FOR_STRING, forwardFor);
HttpResponse result = client.execute(get);
assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
JSONObject responseData = (JSONObject) JSONValue.parse(HttpClientUtils.readResponse(result));
assertEquals(forwardFor + ":0", responseData.get("remoteAddr"));
assertEquals(forwardFor, responseData.get("remoteHost"));
assertEquals("localhost:" + port, responseData.get("host"));
assertEquals(forwardFor, ((JSONObject) responseData.get("headers")).get(Headers.X_FORWARDED_FOR_STRING));
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations