Skip to content

Commit

Permalink
Icon servlet: Set Cache-Control header to enable icon caching (#4336)
Browse files Browse the repository at this point in the history
I have removed the Modified-Since handling as it did not have an effect due to the missing Cache-Control header,
and instead added Cache-Control with a max-age set.
This enables "forever" caching of icons, which should be fine since they are static assets.

Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 authored Aug 4, 2024
1 parent 289f063 commit 1ce5b37
Showing 1 changed file with 1 addition and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -63,8 +62,6 @@ public class IconServlet extends HttpServlet {
static final String PARAM_ANY_FORMAT = "anyFormat";
static final String PARAM_STATE = "state";

private long startupTime;

protected String defaultIconSetId = "classic";

private final List<IconProvider> iconProvider = new ArrayList<>();
Expand All @@ -80,7 +77,6 @@ public void removeIconProvider(IconProvider iconProvider) {

@Activate
protected void activate(Map<String, Object> config) {
startupTime = System.currentTimeMillis();
modified(config);
}

Expand All @@ -94,11 +90,6 @@ protected void modified(Map<String, Object> config) {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (req.getDateHeader("If-Modified-Since") > startupTime) {
resp.setStatus(304);
return;
}

String category = getCategory(req);
if (category.isEmpty()) {
logger.debug("URI must start with '{}' but is '{}'", SERVLET_PATH, req.getRequestURI());
Expand Down Expand Up @@ -148,7 +139,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
}

resp.setContentType(Format.SVG.equals(format) ? "image/svg+xml" : "image/png");
resp.setDateHeader("Last-Modified", Instant.now().toEpochMilli());
resp.setHeader("Cache-Control", "max-age=31536000");
is.transferTo(resp.getOutputStream());
resp.flushBuffer();
} catch (IOException e) {
Expand Down

0 comments on commit 1ce5b37

Please sign in to comment.