public void testClientInitiated() throws Exception {
IServer server = new HttpServer(0, new RequestHandler(), SSLTestContextFactory.getSSLContext(), false);
server.start();
GetRequest request = new GetRequest("/");
request.setHeader("Host", "localhost");
request.setHeader("User-Agent", "me");
request.setHeader("Upgrade", "TLS/1.0");
request.setHeader("Connection", "Upgrade");
IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort(), SSLTestContextFactory.getSSLContext(), false);
con.write(request.toString());
String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
Assert.assertTrue(header.indexOf("101") != -1);
Assert.assertTrue(header.indexOf("Upgrade: TLS/1.0, HTTP/1.1") != -1);
System.out.println("activating secured mode");
con.activateSecuredMode();
QAUtil.sleep(500);
Assert.assertTrue(con.isSecure());
System.out.println("send 2.te request");
request = new GetRequest("/");
request.setHeader("Host", "localhost");
request.setHeader("User-Agent", "me");
con.write(request.toString());
header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
System.out.println("got 2.te response header");
int contentLength = QAUtil.readContentLength(header);