public void testHead() throws Exception
{
Server server = new Server();
try
{
SocketConnector socketConnector = new SocketConnector();
socketConnector.setPort(0);
server.addConnector(socketConnector);
server.addHandler(new AbstractHandler()
{
public void handle(String string, HttpServletRequest request, HttpServletResponse response, int i) throws IOException, ServletException
{
response.setStatus(200);
response.setContentType("text/plain");
PrintWriter w = response.getWriter();
w.flush();
w.println("Geht");
w.flush();
w.println("Doch");
((Request) request).setHandled(true);
}
});
server.start();
Socket socket = new Socket("localhost",socketConnector.getLocalPort());
socket.getOutputStream().write("HEAD / HTTP/1.1\r\nHost: localhost\r\n\r\n".getBytes());
socket.getOutputStream().write("GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n".getBytes());
socket.getOutputStream().flush();
LineNumberReader reader = new LineNumberReader(new InputStreamReader(socket.getInputStream()));