Applied image headers customization to the new ViewFavicon servlet.

This commit is contained in:
luccioman 2016-10-14 14:05:38 +02:00
parent d16e57b41e
commit a588ed7628

View File

@ -930,16 +930,7 @@ public class YaCyDefaultServlet extends HttpServlet {
result = RasterPlotter.exportImage(bi, targetExt);
}
boolean staticImage = target.equals("/ViewImage.png");
if (staticImage) {
if (response.containsHeader(HeaderFramework.LAST_MODIFIED)) {
response.getHeaders(HeaderFramework.LAST_MODIFIED).clear(); // if this field is present, the reload-time is a 10% fraction of ttl and other caching headers do not work
}
// cache-control: allow shared caching (i.e. proxies) and set expires age for cache
response.setHeader(HeaderFramework.CACHE_CONTROL, "public, max-age=" + Integer.toString(600)); // seconds; ten minutes
}
updateRespHeadersForImages(target, response);
final String mimeType = Classification.ext2mime(targetExt, MimeTypes.Type.TEXT_HTML.asString());
response.setContentType(mimeType);
response.setContentLength(result.length());
@ -951,6 +942,9 @@ public class YaCyDefaultServlet extends HttpServlet {
}
if (tmp instanceof InputStream) {
/* Images and favicons can also be written directly from an inputStream */
updateRespHeadersForImages(target, response);
writeInputStream(response, targetExt, (InputStream)tmp);
return;
}
@ -1054,6 +1048,22 @@ public class YaCyDefaultServlet extends HttpServlet {
}
}
/**
* Eventually update response headers for image resources
* @param target the query target
* @param response servlet response to eventually update
*/
private void updateRespHeadersForImages(String target, HttpServletResponse response) {
if (target.equals("/ViewImage.png") || target.equals("/ViewFavicon.png")) {
if (response.containsHeader(HeaderFramework.LAST_MODIFIED)) {
response.getHeaders(HeaderFramework.LAST_MODIFIED).clear(); // if this field is present, the reload-time is a 10% fraction of ttl and other caching headers do not work
}
// cache-control: allow shared caching (i.e. proxies) and set expires age for cache
response.setHeader(HeaderFramework.CACHE_CONTROL, "public, max-age=" + Integer.toString(600)); // seconds; ten minutes
}
}
/**
* Write input stream content to response and close input stream.