boolean keepAlive = "keep-alive".equalsIgnoreCase(request
.getParam("Connection"));
ByteBuffer content = getContent(request.getRequestURI());
HttpResponse response = new HttpResponse();
response.setVersion(request.getVersion());
if (content == null) {
response.setStatusCode(404);
response.setReasonPhrase("Not Found");
response.setParam("Content-Type", "text/plain");
response.setParam("Content-Length", String
.valueOf(NOT_FOUND.length));
response.setContent(NOT_FOUND);
} else {
response.setStatusCode(200);
response.setReasonPhrase("OK");
response.setParam("Content-Type", mimeMap.getContentTypeFor(request
.getRequestURI()));
response.setParam("Content-Length", String.valueOf(content
.remaining()));
}
response.setParam("Server", "Cindy Http Server");
response.setParam("Connection", keepAlive ? "keep-alive" : "close");
Future future = session.send(response); // send http header
if (content != null)
future = session.flush(new DefaultPacket(content)); // send content
if (!keepAlive)