use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class LoadBalancingProxyHTTP2TestCase method testHeadersAreLowercase.
@Test
public void testHeadersAreLowercase() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/name");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
Header header = result.getFirstHeader("x-custom-header");
Assert.assertEquals("x-custom-header", header.getName());
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class LoadBalancingProxyWithCustomHostSelectorTestCase method testDistributeLoadToGivenHost.
// https://issues.jboss.org/browse/UNDERTOW-289
@Test
public void testDistributeLoadToGivenHost() throws Throwable {
final StringBuilder resultString = new StringBuilder();
for (int i = 0; i < 6; ++i) {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/name");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
resultString.append(HttpClientUtils.readResponse(result));
resultString.append(' ');
} finally {
client.getConnectionManager().shutdown();
}
}
Assert.assertTrue(resultString.toString().contains("server1"));
Assert.assertFalse(resultString.toString().contains("server2"));
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ProxyHandlerXForwardedForTestCase method testXForwarded.
@Test
public void testXForwarded() throws Exception {
setProxyHandler(false, false);
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/x-forwarded");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals(port, Integer.parseInt(result.getFirstHeader(Headers.X_FORWARDED_PORT.toString()).getValue()));
Assert.assertEquals("http", result.getFirstHeader(Headers.X_FORWARDED_PROTO.toString()).getValue());
Assert.assertEquals("localhost", result.getFirstHeader(Headers.X_FORWARDED_HOST.toString()).getValue());
Assert.assertEquals(DefaultServer.getDefaultServerAddress().getAddress().getHostAddress(), result.getFirstHeader(Headers.X_FORWARDED_FOR.toString()).getValue());
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ProxyHandlerXForwardedForTestCase method testReuseXForwarded.
@Test
public void testReuseXForwarded() throws Exception {
setProxyHandler(false, true);
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/x-forwarded");
get.addHeader(Headers.X_FORWARDED_FOR.toString(), "50.168.245.32");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals(port, Integer.parseInt(result.getFirstHeader(Headers.X_FORWARDED_PORT.toString()).getValue()));
Assert.assertEquals("http", result.getFirstHeader(Headers.X_FORWARDED_PROTO.toString()).getValue());
Assert.assertEquals("localhost", result.getFirstHeader(Headers.X_FORWARDED_HOST.toString()).getValue());
Assert.assertEquals("50.168.245.32," + DefaultServer.getDefaultServerAddress().getAddress().getHostAddress(), result.getFirstHeader(Headers.X_FORWARDED_FOR.toString()).getValue());
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class AccessLogTestCase method testRemoteAddress.
@Test
public void testRemoteAddress() throws IOException, InterruptedException {
latch = new CountDownLatch(1);
DefaultServer.setRootHandler(new StoredResponseHandler(new AccessLogHandler(HELLO_HANDLER, RECEIVER, "Remote address %a Code %s test-header %{i,test-header} %{STORED_RESPONSE}", AccessLogFileTestCase.class.getClassLoader())));
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
get.addHeader("test-header", "test-value");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals("HelloResponse", HttpClientUtils.readResponse(result));
latch.await(10, TimeUnit.SECONDS);
Assert.assertEquals("Remote address " + DefaultServer.getDefaultServerAddress().getAddress().getHostAddress() + " Code 200 test-header test-value HelloResponse", message);
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations