Search in sources :

Example 6 with TestHttpClient

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();
    }
}
Also used : JSONObject(net.minidev.json.JSONObject) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) TestHttpClient(testutils.TestHttpClient) Test(org.junit.jupiter.api.Test)

Aggregations

HttpResponse (org.apache.http.HttpResponse)6 HttpGet (org.apache.http.client.methods.HttpGet)6 TestHttpClient (testutils.TestHttpClient)6 JSONObject (net.minidev.json.JSONObject)5 Test (org.junit.jupiter.api.Test)5 Header (org.apache.http.Header)1 LaxRedirectStrategy (org.apache.http.impl.client.LaxRedirectStrategy)1