throw new RuntimeException(e);
}
}
public void serveStatic(GrizzlyRequest grizzlyRequest, GrizzlyResponse grizzlyResponse, RenderStatic renderStatic) {
VirtualFile file = Play.getVirtualFile(renderStatic.file);
if (file == null || file.isDirectory() || !file.exists()) {
serve404(grizzlyRequest, grizzlyResponse, new NotFound("The file " + renderStatic.file + " does not exist"));
} else {
grizzlyResponse.setContentType(MimeTypes.getContentType(file.getName()));
boolean raw = false;
for (PlayPlugin plugin : Play.plugins) {
if (plugin.serveStatic(file, Request.current(), Response.current())) {
raw = true;
break;
}
}
try {
if (raw) {
copyResponse(Request.current(), Response.current(), grizzlyRequest, grizzlyResponse);
} else {
if (Play.mode == Play.Mode.DEV) {
grizzlyResponse.setHeader("Cache-Control", "no-cache");
grizzlyResponse.setHeader("Content-Length", String.valueOf(file.length()));
if (!grizzlyRequest.getMethod().equals("HEAD")) {
copyStream(grizzlyResponse, file.inputstream());
} else {
copyStream(grizzlyResponse, new ByteArrayInputStream(new byte[0]));
}
} else {
long last = file.lastModified();
String etag = "\"" + last + "-" + file.hashCode() + "\"";
if (!isModified(etag, last, grizzlyRequest)) {
grizzlyResponse.setHeader("Etag", etag);
grizzlyResponse.setStatus(304);
} else {
grizzlyResponse.setHeader("Last-Modified", Utils.getHttpDateFormatter().format(new Date(last)));
grizzlyResponse.setHeader("Cache-Control", "max-age=" + Play.configuration.getProperty("http.cacheControl", "3600"));
grizzlyResponse.setHeader("Etag", etag);
copyStream(grizzlyResponse, file.inputstream());
}
}
}
} catch (IOException e) {