Replaced the "Restarts" class with individual restart classes.
[jsvc.git] / src / dolda / jsvc / util / Cache.java
CommitLineData
60ef2885
FT
1package dolda.jsvc.util;
2
3import dolda.jsvc.*;
4import java.util.*;
5
6public class Cache {
7 public static void checkmtime(Request req, long mtime) {
8 /* Since the HTTP time format is (reasonably enough) precise
9 * only to seconds, any extra milliseconds must be trimmed
10 * off, or the mtime will almost certainly not match. */
ffbaba01 11 final Date mdate = new Date((mtime / 1000) * 1000);
60ef2885
FT
12 String ims = req.inheaders().get("If-Modified-Since");
13 if(ims != null) {
14 Date cldate;
15 try {
16 cldate = Http.parsedate(ims);
17 } catch(java.text.ParseException e) {
4126b9f4 18 throw(new ClientError("The If-Modified-Since header is not parseable."));
60ef2885
FT
19 }
20 if(mdate.compareTo(cldate) <= 0) {
ffbaba01
FT
21 throw(new RequestRestart() {
22 public void respond(Request req) {
23 req.status(304);
24 req.outheaders().put("Content-Length", "0");
25 req.outheaders().put("Last-Modified", Http.fmtdate(mdate));
26 }
27 });
60ef2885
FT
28 }
29 }
30 req.outheaders().put("Last-Modified", Http.fmtdate(mdate));
31 }
32}