diff options
author | 2021-10-02 02:11:31 +0200 | |
---|---|---|
committer | 2021-10-02 02:11:31 +0200 | |
commit | b834db0fd424e7ab02fcd5e509d855f2d97863bd (patch) | |
tree | b56ce9b8f752d8ca98e1d9082c63542e5dd993c1 /language-web/src/main/java/org | |
parent | feat: skeleton for language to store mapping (diff) | |
download | refinery-b834db0fd424e7ab02fcd5e509d855f2d97863bd.tar.gz refinery-b834db0fd424e7ab02fcd5e509d855f2d97863bd.tar.zst refinery-b834db0fd424e7ab02fcd5e509d855f2d97863bd.zip |
perf(web): split off CodeMirror chunks
Also optimizes statis asset caching.
Diffstat (limited to 'language-web/src/main/java/org')
-rw-r--r-- | language-web/src/main/java/org/eclipse/viatra/solver/language/web/CacheControlFilter.java | 55 | ||||
-rw-r--r-- | language-web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java | 3 |
2 files changed, 58 insertions, 0 deletions
diff --git a/language-web/src/main/java/org/eclipse/viatra/solver/language/web/CacheControlFilter.java b/language-web/src/main/java/org/eclipse/viatra/solver/language/web/CacheControlFilter.java new file mode 100644 index 00000000..41b8e5bf --- /dev/null +++ b/language-web/src/main/java/org/eclipse/viatra/solver/language/web/CacheControlFilter.java | |||
@@ -0,0 +1,55 @@ | |||
1 | package org.eclipse.viatra.solver.language.web; | ||
2 | |||
3 | import java.io.IOException; | ||
4 | import java.util.regex.Pattern; | ||
5 | |||
6 | import javax.servlet.Filter; | ||
7 | import javax.servlet.FilterChain; | ||
8 | import javax.servlet.FilterConfig; | ||
9 | import javax.servlet.ServletException; | ||
10 | import javax.servlet.ServletRequest; | ||
11 | import javax.servlet.ServletResponse; | ||
12 | import javax.servlet.http.HttpServletRequest; | ||
13 | import javax.servlet.http.HttpServletResponse; | ||
14 | |||
15 | public class CacheControlFilter implements Filter { | ||
16 | |||
17 | private static final String CACHE_CONTROL_HEADER = "Cache-Control"; | ||
18 | |||
19 | private static final String EXPIRES_HEADER = "Expires"; | ||
20 | |||
21 | private static final Pattern CACHE_URI_PATTERN = Pattern.compile(".*\\.(css|gif|js|map|png|svg|woff2)"); | ||
22 | |||
23 | private static final long EXPIRY = 31536000; | ||
24 | |||
25 | private static final String CACHE_CONTROL_CACHE_VALUE = "public, max-age: " + EXPIRY + ", immutable"; | ||
26 | |||
27 | private static final String CACHE_CONTROL_NO_CACHE_VALUE = "no-cache, no-store, max-age: 0, must-revalidate"; | ||
28 | |||
29 | @Override | ||
30 | public void init(FilterConfig filterConfig) throws ServletException { | ||
31 | // Nothing to initialize. | ||
32 | } | ||
33 | |||
34 | @Override | ||
35 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
36 | throws IOException, ServletException { | ||
37 | if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { | ||
38 | var httpRequest = (HttpServletRequest) request; | ||
39 | var httpResponse = (HttpServletResponse) response; | ||
40 | if (CACHE_URI_PATTERN.matcher(httpRequest.getRequestURI()).matches()) { | ||
41 | httpResponse.setHeader(CACHE_CONTROL_HEADER, CACHE_CONTROL_CACHE_VALUE); | ||
42 | httpResponse.setDateHeader(EXPIRES_HEADER, System.currentTimeMillis() + EXPIRY * 1000L); | ||
43 | } else { | ||
44 | httpResponse.setHeader(CACHE_CONTROL_HEADER, CACHE_CONTROL_NO_CACHE_VALUE); | ||
45 | httpResponse.setDateHeader(EXPIRES_HEADER, 0); | ||
46 | } | ||
47 | } | ||
48 | chain.doFilter(request, response); | ||
49 | } | ||
50 | |||
51 | @Override | ||
52 | public void destroy() { | ||
53 | // Nothing to dispose. | ||
54 | } | ||
55 | } | ||
diff --git a/language-web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java b/language-web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java index d92c7735..a6d58f95 100644 --- a/language-web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java +++ b/language-web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java | |||
@@ -8,8 +8,10 @@ import java.io.IOException; | |||
8 | import java.net.InetSocketAddress; | 8 | import java.net.InetSocketAddress; |
9 | import java.net.URI; | 9 | import java.net.URI; |
10 | import java.net.URISyntaxException; | 10 | import java.net.URISyntaxException; |
11 | import java.util.EnumSet; | ||
11 | import java.util.Set; | 12 | import java.util.Set; |
12 | 13 | ||
14 | import javax.servlet.DispatcherType; | ||
13 | import javax.servlet.SessionTrackingMode; | 15 | import javax.servlet.SessionTrackingMode; |
14 | 16 | ||
15 | import org.eclipse.jetty.server.Server; | 17 | import org.eclipse.jetty.server.Server; |
@@ -42,6 +44,7 @@ public class ServerLauncher { | |||
42 | handler.setWelcomeFiles(new String[] { "index.html" }); | 44 | handler.setWelcomeFiles(new String[] { "index.html" }); |
43 | addDefaultServlet(handler); | 45 | addDefaultServlet(handler); |
44 | } | 46 | } |
47 | handler.addFilter(CacheControlFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); | ||
45 | server.setHandler(handler); | 48 | server.setHandler(handler); |
46 | } | 49 | } |
47 | 50 | ||