}
public void service(Context context, Resource resource) throws Exception
{
HttpServletRequest request = context.getRequest();
HttpServletResponse response = context.getResponse();
context.log().debug(request.getMethod()+' '+context.getAddress().getPathinfo());
long last_modified = resource.getLastModified();
if (last_modified > 0) {
String if_modified_since = request.getHeader("if-modified-since");
if (if_modified_since != null) {
HttpDate ifmod = new HttpDate();
if (ifmod.parse(if_modified_since)) {
HttpDate mod = new HttpDate(last_modified);
if (mod.after(ifmod)) {
response.setStatus(304);
response.setContentLength(0);
return;
}
}
}
}
int contentLength = (int)resource.getLength();
OutputStream output = context.getOutputStream();
response.setContentType(resource.getContentType());
response.setContentLength(contentLength);
response.setDateHeader("Last-Modified", last_modified);
resource.writeTo(output);
output.flush();
resource.close();
}