Skip to content

Commit aa8fe8c

Browse files
committed
feat: don't redirect service worker precache requests
1 parent e9645e2 commit aa8fe8c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/filter/GlobalShellFilter.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,15 @@ private boolean redirectLegacyAppPaths(
9999
boolean matchesPattern = m.find();
100100
boolean isIndexPath = path.endsWith("/") || path.endsWith("/index.html");
101101
boolean hasRedirectFalse = queryString != null && queryString.contains("redirect=false");
102-
if (matchesPattern && isIndexPath && !hasRedirectFalse) {
102+
103+
// Referer header is set by the browser when the request is made from a service worker
104+
// TODO: Enforce that apps must use the path 'service-worker.js' for service worker
105+
// registration perhaps by checking the 'Service-Worker' request header, see
106+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Service-Worker
107+
String referer = request.getHeader("Referer");
108+
boolean sentFromServiceWorker = referer != null && referer.endsWith("service-worker.js");
109+
110+
if (matchesPattern && isIndexPath && !hasRedirectFalse && !sentFromServiceWorker) {
103111
String appName = m.group(1);
104112
response.sendRedirect(request.getContextPath() + GLOBAL_SHELL_PATH_PREFIX + appName);
105113
log.debug("Redirecting to global shell");

0 commit comments

Comments
 (0)