RequestHandler srvHdl = new RequestHandler();
IServer server = new HttpServer(srvHdl);
server.start();
IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
con.write("GET / HTTP/1.1\r\n" +
"Content-Length: 5 \r\n" +
"X-MyHeader: this is a text \r\n" +
"Host: localhost\r\n" +
"User-Agent: me\r\n" +
"\r\n" +
"12345");
String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
int contentLength = QAUtil.readContentLength(header);
String body = con.readStringByLength(contentLength);
Assert.assertTrue(header.indexOf("200") != -1);
Assert.assertEquals("OK", body);
Assert.assertEquals("this is a text", srvHdl.getRequest().getHeader("X-MyHeader"));
con.close();
server.close();
}