diff options
Diffstat (limited to 'subprojects/language-web')
-rw-r--r-- | subprojects/language-web/src/main/java/tools/refinery/language/web/CacheControlFilter.java | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/CacheControlFilter.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/CacheControlFilter.java index b13ae95d..8ac8a21e 100644 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/CacheControlFilter.java +++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/CacheControlFilter.java | |||
@@ -2,6 +2,7 @@ package tools.refinery.language.web; | |||
2 | 2 | ||
3 | import java.io.IOException; | 3 | import java.io.IOException; |
4 | import java.time.Duration; | 4 | import java.time.Duration; |
5 | import java.util.Set; | ||
5 | import java.util.regex.Pattern; | 6 | import java.util.regex.Pattern; |
6 | 7 | ||
7 | import org.eclipse.jetty.http.HttpHeader; | 8 | import org.eclipse.jetty.http.HttpHeader; |
@@ -16,7 +17,10 @@ import jakarta.servlet.http.HttpServletRequest; | |||
16 | import jakarta.servlet.http.HttpServletResponse; | 17 | import jakarta.servlet.http.HttpServletResponse; |
17 | 18 | ||
18 | public class CacheControlFilter implements Filter { | 19 | public class CacheControlFilter implements Filter { |
19 | private static final Pattern CACHE_URI_PATTERN = Pattern.compile(".*\\.(css|gif|js|map|png|svg|woff2)"); | 20 | private static final Pattern CACHE_URI_PATTERN = Pattern.compile(".*\\.(css|gif|js|map|png|svg|woff2?)"); |
21 | |||
22 | private static final Set<String> CACHE_URI_DENYLIST = Set.of("apple-touch-icon.png", "favicon.png", "favicon.svg", | ||
23 | "favicon-96x96.png", "icon-any.svg", "icon-192x192.png", "icon-512x512.png", "mask-icon.svg", "sw.js"); | ||
20 | 24 | ||
21 | private static final Duration EXPIRY = Duration.ofDays(365); | 25 | private static final Duration EXPIRY = Duration.ofDays(365); |
22 | 26 | ||
@@ -33,7 +37,8 @@ public class CacheControlFilter implements Filter { | |||
33 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | 37 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) |
34 | throws IOException, ServletException { | 38 | throws IOException, ServletException { |
35 | if (request instanceof HttpServletRequest httpRequest && response instanceof HttpServletResponse httpResponse) { | 39 | if (request instanceof HttpServletRequest httpRequest && response instanceof HttpServletResponse httpResponse) { |
36 | if (CACHE_URI_PATTERN.matcher(httpRequest.getRequestURI()).matches()) { | 40 | var requestURI = httpRequest.getRequestURI(); |
41 | if (CACHE_URI_PATTERN.matcher(requestURI).matches() && !CACHE_URI_DENYLIST.contains(requestURI)) { | ||
37 | httpResponse.setHeader(HttpHeader.CACHE_CONTROL.asString(), CACHE_CONTROL_CACHE_VALUE); | 42 | httpResponse.setHeader(HttpHeader.CACHE_CONTROL.asString(), CACHE_CONTROL_CACHE_VALUE); |
38 | httpResponse.setDateHeader(HttpHeader.EXPIRES.asString(), | 43 | httpResponse.setDateHeader(HttpHeader.EXPIRES.asString(), |
39 | System.currentTimeMillis() + EXPIRY.toMillis()); | 44 | System.currentTimeMillis() + EXPIRY.toMillis()); |