Some fixes in FilePage
This commit is contained in:
parent
23090d2bd5
commit
e116f999c5
1 changed files with 20 additions and 19 deletions
|
|
@ -82,8 +82,7 @@ public class HttpFilePage implements HttpPage{
|
|||
// Is the root only one file or a folder
|
||||
if (resource_root.isFile()) {
|
||||
deliverFileWithCache(headers, resource_root, out);
|
||||
}
|
||||
else { // Resource root is a folder
|
||||
} else { // Resource root is a folder
|
||||
File file = new File(resource_root,
|
||||
headers.getRequestURL());
|
||||
if (file.getCanonicalPath().startsWith(resource_root.getCanonicalPath())) {
|
||||
|
|
@ -114,8 +113,7 @@ public class HttpFilePage implements HttpPage{
|
|||
else {
|
||||
deliverFileWithCache(headers, file, out);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new SecurityException("File is outside of root directory: root=" + resource_root.getAbsolutePath() + " file=" + file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
|
@ -136,15 +134,18 @@ public class HttpFilePage implements HttpPage{
|
|||
private void deliverFileWithCache(HttpHeader headers, File file, HttpPrintStream out) throws IOException {
|
||||
String eTag = getFileHash(file);
|
||||
out.setHeader("Cache-Control", "max-age=" + MAX_CACHE_AGE_SECONDS);
|
||||
|
||||
if (eTag != null) {
|
||||
out.setHeader("ETag", "\"" + eTag + "\"");
|
||||
|
||||
if (eTag != null && headers.getHeader("If-None-Match") != null &&
|
||||
if (headers.getHeader("If-None-Match") != null &&
|
||||
eTag.equals(StringUtil.trimQuotes(headers.getHeader("If-None-Match")))) { // File has not changed
|
||||
out.setResponseStatusCode(304);
|
||||
} else {
|
||||
deliverFile(file, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void deliverFile(File file, HttpPrintStream out) throws IOException {
|
||||
String fileExt = FileUtil.getFileExtension(file);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue