RequestHandlerChain chain = new RequestHandlerChain();
chain.addLast(interceptor);
ContinueHandler hdl = new ContinueHandler();
chain.addLast(hdl);
HttpServer server = new HttpServer(chain);
server.start();
IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
con.write("POST / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"User-Agent: me\r\n" +
"Expect: 100-Continue\r\n" +
"Content-Length: 2000\r\n" +
"\r\n");
String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
Assert.assertTrue(header.indexOf("100") != -1);
Assert.assertTrue(hdl.is100ContinueSent());
Assert.assertTrue(header.indexOf("X-Intercepted: true") != -1);
con.write(QAUtil.generateByteArray(2000));
header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
Assert.assertTrue(header.indexOf("200") != -1);
Assert.assertTrue(header.indexOf("X-Intercepted") != -1);
int length = QAUtil.readContentLength(header);
String txt = con.readStringByLength(length);
Assert.assertEquals("OK", txt);
con.close();
server.close();
}