use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class DefaultServletCachingTestCase method testRangeRequest.
@Test
public void testRangeRequest() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
String fileName = "range.html";
Path f = tmpDir.resolve(fileName);
Files.write(f, "hello".getBytes());
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/range.html");
get.addHeader("range", "bytes=2-3");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.PARTIAL_CONTENT, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("ll", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class DefaultServletTestCase method testResourceWithFilter.
@Test
public void testResourceWithFilter() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/filterpath/filtered.txt");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("Hello Stuart", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class DefaultServletTestCase method testIfMoodifiedSince.
@Test
public void testIfMoodifiedSince() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/index.html");
//UNDERTOW-458
get.addHeader("date-header", "Fri, 10 Oct 2014 21:35:55 CEST");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertTrue(response.contains("Redirected home page"));
String lm = result.getHeaders("Last-Modified")[0].getValue();
System.out.println(lm);
Assert.assertTrue(lm.endsWith("GMT"));
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/index.html");
get.addHeader("IF-Modified-Since", lm);
result = client.execute(get);
Assert.assertEquals(StatusCodes.NOT_MODIFIED, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertFalse(response.contains("Redirected home page"));
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class DefaultServletTestCase method testRangeRequest.
@Test
public void testRangeRequest() throws IOException, InterruptedException {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/range.txt";
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/index.html");
get.addHeader(Headers.RANGE_STRING, "bytes=2-3");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.PARTIAL_CONTENT, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("--", response);
get = new HttpGet(uri);
get.addHeader(Headers.RANGE_STRING, "bytes=3-100");
result = client.execute(get);
Assert.assertEquals(StatusCodes.PARTIAL_CONTENT, result.getStatusLine().getStatusCode());
response = EntityUtils.toString(result.getEntity());
Assert.assertEquals("3456789", response);
Assert.assertEquals("bytes 3-9/10", result.getFirstHeader(Headers.CONTENT_RANGE_STRING).getValue());
get = new HttpGet(uri);
get.addHeader(Headers.RANGE_STRING, "bytes=3-9");
result = client.execute(get);
Assert.assertEquals(StatusCodes.PARTIAL_CONTENT, result.getStatusLine().getStatusCode());
response = EntityUtils.toString(result.getEntity());
Assert.assertEquals("3456789", response);
Assert.assertEquals("bytes 3-9/10", result.getFirstHeader(Headers.CONTENT_RANGE_STRING).getValue());
get = new HttpGet(uri);
get.addHeader(Headers.RANGE_STRING, "bytes=2-3");
result = client.execute(get);
Assert.assertEquals(StatusCodes.PARTIAL_CONTENT, result.getStatusLine().getStatusCode());
response = EntityUtils.toString(result.getEntity());
Assert.assertEquals("23", response);
Assert.assertEquals("bytes 2-3/10", result.getFirstHeader(Headers.CONTENT_RANGE_STRING).getValue());
get = new HttpGet(uri);
get.addHeader(Headers.RANGE_STRING, "bytes=0-0");
result = client.execute(get);
Assert.assertEquals(StatusCodes.PARTIAL_CONTENT, result.getStatusLine().getStatusCode());
response = EntityUtils.toString(result.getEntity());
Assert.assertEquals("0", response);
Assert.assertEquals("bytes 0-0/10", result.getFirstHeader(Headers.CONTENT_RANGE_STRING).getValue());
get = new HttpGet(uri);
get.addHeader(Headers.RANGE_STRING, "bytes=1-");
result = client.execute(get);
Assert.assertEquals(StatusCodes.PARTIAL_CONTENT, result.getStatusLine().getStatusCode());
response = EntityUtils.toString(result.getEntity());
Assert.assertEquals("123456789", response);
Assert.assertEquals("bytes 1-9/10", result.getFirstHeader(Headers.CONTENT_RANGE_STRING).getValue());
get = new HttpGet(uri);
get.addHeader(Headers.RANGE_STRING, "bytes=0-");
result = client.execute(get);
Assert.assertEquals(StatusCodes.PARTIAL_CONTENT, result.getStatusLine().getStatusCode());
response = EntityUtils.toString(result.getEntity());
Assert.assertEquals("0123456789", response);
Assert.assertEquals("bytes 0-9/10", result.getFirstHeader(Headers.CONTENT_RANGE_STRING).getValue());
get = new HttpGet(uri);
get.addHeader(Headers.RANGE_STRING, "bytes=9-");
result = client.execute(get);
Assert.assertEquals(StatusCodes.PARTIAL_CONTENT, result.getStatusLine().getStatusCode());
response = EntityUtils.toString(result.getEntity());
Assert.assertEquals("9", response);
Assert.assertEquals("bytes 9-9/10", result.getFirstHeader(Headers.CONTENT_RANGE_STRING).getValue());
get = new HttpGet(uri);
get.addHeader(Headers.RANGE_STRING, "bytes=-1");
result = client.execute(get);
Assert.assertEquals(StatusCodes.PARTIAL_CONTENT, result.getStatusLine().getStatusCode());
response = EntityUtils.toString(result.getEntity());
Assert.assertEquals("9", response);
Assert.assertEquals("bytes 9-9/10", result.getFirstHeader(Headers.CONTENT_RANGE_STRING).getValue());
get = new HttpGet(uri);
get.addHeader(Headers.RANGE_STRING, "bytes=-100");
result = client.execute(get);
Assert.assertEquals(StatusCodes.PARTIAL_CONTENT, result.getStatusLine().getStatusCode());
response = EntityUtils.toString(result.getEntity());
Assert.assertEquals("0123456789", response);
Assert.assertEquals("bytes 0-9/10", result.getFirstHeader(Headers.CONTENT_RANGE_STRING).getValue());
get = new HttpGet(uri);
get.addHeader(Headers.RANGE_STRING, "bytes=99-100");
result = client.execute(get);
Assert.assertEquals(StatusCodes.REQUEST_RANGE_NOT_SATISFIABLE, result.getStatusLine().getStatusCode());
response = EntityUtils.toString(result.getEntity());
Assert.assertEquals("", response);
Assert.assertEquals("bytes */10", result.getFirstHeader(Headers.CONTENT_RANGE_STRING).getValue());
get = new HttpGet(uri);
get.addHeader(Headers.RANGE_STRING, "bytes=2-1");
result = client.execute(get);
Assert.assertEquals(StatusCodes.REQUEST_RANGE_NOT_SATISFIABLE, result.getStatusLine().getStatusCode());
response = EntityUtils.toString(result.getEntity());
Assert.assertEquals("", response);
Assert.assertEquals("bytes */10", result.getFirstHeader(Headers.CONTENT_RANGE_STRING).getValue());
//test if-range
get = new HttpGet(uri);
get.addHeader(Headers.RANGE_STRING, "bytes=2-3");
get.addHeader(Headers.IF_RANGE_STRING, DateUtils.toDateString(new Date(System.currentTimeMillis() + 1000)));
result = client.execute(get);
Assert.assertEquals(StatusCodes.PARTIAL_CONTENT, result.getStatusLine().getStatusCode());
response = EntityUtils.toString(result.getEntity());
Assert.assertEquals("23", response);
Assert.assertEquals("bytes 2-3/10", result.getFirstHeader(Headers.CONTENT_RANGE_STRING).getValue());
get = new HttpGet(uri);
get.addHeader(Headers.RANGE_STRING, "bytes=2-3");
get.addHeader(Headers.IF_RANGE_STRING, DateUtils.toDateString(new Date(0)));
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = EntityUtils.toString(result.getEntity());
Assert.assertEquals("0123456789", response);
Assert.assertNull(result.getFirstHeader(Headers.CONTENT_RANGE_STRING));
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class DefaultServletTestCase method testDirectoryListing.
@Test
public void testDirectoryListing() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/path");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations