1 package dolda.jsvc.util;
7 public class StaticContent implements Responder {
8 private final Class<?> base;
9 private final String resname;
10 private final boolean dir;
11 private final String mimetype;
13 public StaticContent(Class<?> base, String resname, boolean dir, String mimetype) {
15 this.resname = resname;
17 this.mimetype = mimetype;
20 public StaticContent(String resname, boolean dir, String mimetype) {
21 this(null, resname, dir, mimetype);
24 public void respond(Request req) {
27 nm = resname + "/" + req.path();
33 in = StaticContent.class.getClassLoader().getResourceAsStream(nm);
35 in = base.getResourceAsStream(nm);
38 throw(Restarts.stdresponse(404));
39 Cache.checkmtime(req, req.ctx().starttime());
42 req.outheaders().put("Content-Type", mimetype);
43 Misc.cpstream(in, req.output());
47 } catch(IOException e) {