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, String mimetype) {
15 this.dir = ((this.resname = resname).charAt(resname.length() - 1) == '/');
16 this.mimetype = mimetype;
19 public StaticContent(String resname, String mimetype) {
20 this(null, resname, mimetype);
23 public void respond(Request req) {
26 nm = resname + req.path();
31 in = StaticContent.class.getClassLoader().getResourceAsStream(nm);
33 in = base.getResourceAsStream(nm);
36 throw(new StdResponse(404));
37 Cache.checkmtime(req, req.ctx().starttime());
40 req.outheaders().put("Content-Type", mimetype);
41 Misc.cpstream(in, req.output());
45 } catch(IOException e) {