HttpServer server = new HttpServer(0, chain);
server.setCloseOnSendingError(false);
ConnectionUtils.start(server);
GetRequest req = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
req.setHeader("Host", "localhost");
req.setHeader("User-Agent", "me");
IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
con.write(req.toString());
String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
Assert.assertTrue(header.indexOf("401") != -1);
Assert.assertTrue(header.indexOf("WWW-Authenticate") != -1);
req = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
req.setHeader("Authorization", "Basic YXNkYXNkOmFzZGFzZA==");
con.write(req.toString());
header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
int contentLength = QAUtil.readContentLength(header);
String body = con.readStringByLength(contentLength);