use of org.apache.http.impl.client.CloseableHttpClient 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.impl.client.CloseableHttpClient in project nanohttpd by NanoHttpd.
the class TestNanolets method doOtherMethod.
@Test
public void doOtherMethod() throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpTrace httphead = new HttpTrace("http://localhost:9090/index.html");
CloseableHttpResponse response = httpclient.execute(httphead);
HttpEntity entity = response.getEntity();
String string = new String(readContents(entity), "UTF-8");
Assert.assertEquals("<html><body><h2>Hello world!</h3></body></html>", string);
response.close();
}
use of org.apache.http.impl.client.CloseableHttpClient in project nanohttpd by NanoHttpd.
the class TestCorsHttpServer method testAccessControlAllowHeaderUsesDefaultsWithoutSystemProperty.
@Test
public void testAccessControlAllowHeaderUsesDefaultsWithoutSystemProperty() throws Exception {
Assert.assertNull("no System " + SimpleWebServer.ACCESS_CONTROL_ALLOW_HEADER_PROPERTY_NAME + " shoudl be set", System.getProperty(SimpleWebServer.ACCESS_CONTROL_ALLOW_HEADER_PROPERTY_NAME));
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpOptions httpOption = new HttpOptions("http://localhost:9090/xxx/yyy.html");
CloseableHttpResponse response = httpclient.execute(httpOption);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
Assert.assertEquals("Cors should have added a header: Access-Control-Allow-Headers: " + SimpleWebServer.DEFAULT_ALLOWED_HEADERS, SimpleWebServer.DEFAULT_ALLOWED_HEADERS, response.getLastHeader("Access-Control-Allow-Headers").getValue());
response.close();
}
use of org.apache.http.impl.client.CloseableHttpClient 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.impl.client.CloseableHttpClient in project nanohttpd by NanoHttpd.
the class TestCorsHttpServerWithSingleOrigin method doTestOption.
@Test
public void doTestOption() throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpOptions httpOption = new HttpOptions("http://localhost:9090/xxx/yyy.html");
CloseableHttpResponse response = httpclient.execute(httpOption);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
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());
response.close();
}
Aggregations