add last-modified headers
add flush() at end of scaleImage()
This commit is contained in:
parent
e08d11448e
commit
647bae4020
1 changed files with 15 additions and 0 deletions
|
|
@ -128,13 +128,26 @@ public class AlbumServlet
|
|||
return false;
|
||||
}
|
||||
|
||||
boolean notModified(HttpServletRequest req, File f) {
|
||||
long reqDate = req.getDateHeader("If-Modified-Since");
|
||||
long fDate = f.lastModified();
|
||||
return reqDate > 0 && fDate > 0 && fDate <= reqDate;
|
||||
}
|
||||
|
||||
synchronized void scaleImage(HttpServletRequest req, HttpServletResponse res, File file, Thumbnail thumbnail, String size) throws IOException {
|
||||
|
||||
if (notModified(req, file)) {
|
||||
res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
|
||||
System.out.println(file.getName() + " not modified (based on date)");
|
||||
return;
|
||||
}
|
||||
String fileEtag = thumbnail.getEtag() + "-" + size;
|
||||
if (etagMatches(req, fileEtag)) {
|
||||
res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
|
||||
System.out.println(file.getName() + " not modified (based on etag)");
|
||||
return;
|
||||
}
|
||||
res.setDateHeader("Last-Modified", file.lastModified());
|
||||
res.setHeader("ETag", fileEtag);
|
||||
|
||||
Dimension orig = thumbnail.getSize();
|
||||
|
|
@ -213,6 +226,8 @@ public class AlbumServlet
|
|||
writer.setOutput(ios);
|
||||
// writer.write(null, new IIOImage(buf2, null, null), wParam);
|
||||
writer.write(buf2);
|
||||
ios.flush();
|
||||
res.getOutputStream().close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue