mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
Applied image headers customization to the new ViewFavicon servlet.
This commit is contained in:
parent
d16e57b41e
commit
a588ed7628
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user