{
// Parse request from InputStream
HttpRequest request = parseRequest(socket.getInputStream());
// Create appropriate response
HttpResponse response = handleRequest(request);
// Send response and close connection, if necessary
if (keepAlive(request, response))
{
sendResponse(response, socket.getOutputStream());
server.dispatchRequest(socket);
}
else
{
response.getHeaders().put("Connection", "close");
sendResponse(response, socket.getOutputStream());
socket.close();
}
// We do not return anything here.