X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2Futil%2FStaticContent.java;h=0ef227da8422e46a35e8fa667884516f4760b681;hb=b9089d950e376b3f48c63e69c72a32d4efeba7b0;hp=0d4208ef2ac7f01e40722b0ddf8d8a94759cf08d;hpb=7779099a6c15508f2dd214a7555c66a27f8343ed;p=jsvc.git diff --git a/src/dolda/jsvc/util/StaticContent.java b/src/dolda/jsvc/util/StaticContent.java index 0d4208e..0ef227d 100644 --- a/src/dolda/jsvc/util/StaticContent.java +++ b/src/dolda/jsvc/util/StaticContent.java @@ -10,24 +10,22 @@ public class StaticContent implements Responder { private final boolean dir; private final String mimetype; - public StaticContent(Class base, String resname, boolean dir, String mimetype) { + public StaticContent(Class base, String resname, String mimetype) { this.base = base; - this.resname = resname; - this.dir = dir; + this.dir = ((this.resname = resname).charAt(resname.length() - 1) == '/'); this.mimetype = mimetype; } - public StaticContent(String resname, boolean dir, String mimetype) { - this(null, resname, dir, mimetype); + public StaticContent(String resname, String mimetype) { + this(null, resname, mimetype); } public void respond(Request req) { String nm; - if(dir) { - nm = resname + "/" + req.path(); - } else { + if(dir) + nm = resname + req.path(); + else nm = resname; - } InputStream in; if(base == null) { in = StaticContent.class.getClassLoader().getResourceAsStream(nm); @@ -35,26 +33,11 @@ public class StaticContent implements Responder { in = base.getResourceAsStream(nm); } if(in == null) - throw(Restarts.stdresponse(404)); - String ims = req.inheaders().get("If-Modified-Since"); - Date mtime = new Date((req.ctx().starttime() / 1000) * 1000); - if(ims != null) { - Date d; - try { - d = Http.parsedate(ims); - } catch(java.text.ParseException e) { - throw(Restarts.stdresponse(400)); - } - if(mtime.compareTo(d) <= 0) { - req.status(304); - req.outheaders().put("Content-Length", "0"); - return; - } - } + throw(new StdResponse(404)); + Cache.checkmtime(req, req.ctx().starttime()); try { try { req.outheaders().put("Content-Type", mimetype); - req.outheaders().put("Last-Modified", Http.fmtdate(mtime)); Misc.cpstream(in, req.output()); } finally { in.close();