IServer server = new HttpServer(new RequestHandler());
server.start();
IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
con.write("GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"User-");
QAUtil.sleep(200);
con.write("Agent: me\r\n" +
"\r\n");
QAUtil.sleep(200);
con.write("GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"User-Agent: me\r\n" +
"\r\n");
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);
header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
contentLength = QAUtil.readContentLength(header);
body = con.readStringByLength(contentLength);
Assert.assertTrue(header.indexOf("200") != -1);
Assert.assertEquals("OK", body);
con.close();
server.close();
}