use of org.apache.http.client.methods.HttpGet in project nanohttpd by NanoHttpd.
the class TestNanolets method doMissingHandler.
@Test
public void doMissingHandler() throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://localhost:9090/photos/abc/def");
CloseableHttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String string = new String(readContents(entity), "UTF-8");
Assert.assertEquals("<html><body><h2>The uri is mapped in the router, but no handler is specified. <br> Status: Not implemented!</h3></body></html>", string);
response.close();
}
use of org.apache.http.client.methods.HttpGet in project nanohttpd by NanoHttpd.
the class CookieIntegrationTest method testMultipleCookieSentBackToClient.
@Test
public void testMultipleCookieSentBackToClient() throws Exception {
this.testServer.cookiesToSend.add(new Cookie("name0", "value0", 30));
this.testServer.cookiesToSend.add(new Cookie("name1", "value1", 30));
this.testServer.cookiesToSend.add(new Cookie("name2", "value2", 30));
this.testServer.cookiesToSend.add(new Cookie("name3", "value3", 30));
HttpGet httpget = new HttpGet("http://localhost:8192/");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
this.httpclient.execute(httpget, responseHandler);
assertEquals(4, this.httpclient.getCookieStore().getCookies().size());
}
use of org.apache.http.client.methods.HttpGet in project nanohttpd by NanoHttpd.
the class TestCorsHttpServerWithSingleOrigin method doSomeBasicTest.
@Test
public void doSomeBasicTest() throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://localhost:9090/testdir/test.html");
CloseableHttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String string = new String(readContents(entity), "UTF-8");
Assert.assertNotNull("Cors should have added a header: Access-Control-Allow-Origin", response.getLastHeader("Access-Control-Allow-Origin"));
Assert.assertEquals("Cors should have added a header: Access-Control-Allow-Origin: http://localhost:9090", "http://localhost:9090", response.getLastHeader("Access-Control-Allow-Origin").getValue());
Assert.assertEquals("<html>\n<head>\n<title>dummy</title>\n</head>\n<body>\n\t<h1>it works</h1>\n</body>\n</html>", string);
response.close();
}
use of org.apache.http.client.methods.HttpGet in project nanohttpd by NanoHttpd.
the class TestHttpServer method testRangeHeaderWithStartAndEndPosition.
@Test
public void testRangeHeaderWithStartAndEndPosition() throws ClientProtocolException, IOException {
CloseableHttpResponse response = null;
try {
HttpGet httpGet = new HttpGet("http://localhost:9090/testdir/test.html");
httpGet.addHeader("range", "bytes=10-40");
CloseableHttpClient httpClient = HttpClients.createDefault();
response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
String responseString = new String(readContents(entity), "UTF-8");
Assert.assertThat("The data from the beginning of the file should have been skipped as specified in the 'range' header", responseString, not(containsString("<head>")));
Assert.assertThat("The data from the end of the file should have been skipped as specified in the 'range' header", responseString, not(containsString("</head>")));
Assert.assertEquals("The 'Content-Length' should be the length from the requested start position to end position", "31", response.getHeaders("Content-Length")[0].getValue());
Assert.assertEquals("The 'Contnet-Range' header should contain the correct lengths and offsets based on the range served", "bytes 10-40/84", response.getHeaders("Content-Range")[0].getValue());
Assert.assertEquals("Response status for a successful request with 'range' header should be PARTIAL_CONTENT(206)", 206, response.getStatusLine().getStatusCode());
} finally {
if (response != null) {
response.close();
}
}
}
use of org.apache.http.client.methods.HttpGet in project nanohttpd by NanoHttpd.
the class TestHttpServer method testIndexFileIsShownWhenURLEndsWithDirectory.
@Test
public void testIndexFileIsShownWhenURLEndsWithDirectory() throws ClientProtocolException, IOException {
CloseableHttpResponse response = null;
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("http://localhost:9090/testdir/testdir");
response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
String responseString = new String(readContents(entity), "UTF-8");
Assert.assertThat("When the URL ends with a directory, and if an index.html file is present in that directory," + " the server should respond with that file", responseString, containsString("Simple index file"));
} finally {
if (response != null) {
response.close();
}
}
}
Aggregations