Adding "Expires" headers to improve caching client side.

This commit is contained in:
Knut Forkalsrud 2009-11-08 11:24:59 -08:00
parent f6bea49c02
commit 984c74b63f

View file

@ -69,7 +69,7 @@ public class AlbumServlet
if (pathInfo != null && pathInfo.startsWith(basePrefix)) {
pathInfo = pathInfo.substring(basePrefix.length());
} else {
res.sendError(HttpServletResponse.SC_NOT_FOUND);
res.sendError(HttpServletResponse.SC_NOT_FOUND, "pathinfo=" + pathInfo);
return;
}
@ -153,12 +153,14 @@ public class AlbumServlet
if (notModified(req, file)) {
res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
res.setDateHeader("Expires", System.currentTimeMillis() + (30 * 24 * 3600 * 1000)); // 30 days
System.out.println(file.getName() + " not modified (based on date)");
return;
}
String fileEtag = thumbnail.getEtag() + "-" + size;
if (etagMatches(req, fileEtag)) {
res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
res.setDateHeader("Expires", System.currentTimeMillis() + (30 * 24 * 3600 * 1000)); // 30 days
System.out.println(file.getName() + " not modified (based on etag)");
return;
}
@ -195,6 +197,7 @@ public class AlbumServlet
res.setStatus(HttpServletResponse.SC_OK);
res.setDateHeader("Last-Modified", file.lastModified());
res.setHeader("ETag", fileEtag);
res.setDateHeader("Expires", System.currentTimeMillis() + (30 * 24 * 3600 * 1000)); // 30 days
res.setContentType(cimg.mimeType);
res.setContentLength(cimg.bits.length);
res.getOutputStream().write(cimg.bits);