Package ru.vyarus.guicey.spa.filter
Class SpaUtils
- java.lang.Object
-
- ru.vyarus.guicey.spa.filter.SpaUtils
-
public final class SpaUtils extends java.lang.ObjectCore SPA routes detection logic.- Since:
- 16.01.2019
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voiddoRedirect(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, java.lang.String target)Perform server redirect into root page.static booleanisHtmlRequest(jakarta.servlet.http.HttpServletRequest req)Checks if provided request expects html response (by accept header).static booleanisRootPage(java.lang.String currentPath, java.lang.String rootPath)Note that root path is not the index page, but root mapping path, which will implicitly lead to index page.static booleanisSpaRoute(jakarta.servlet.http.HttpServletRequest req, java.util.regex.Pattern noRedirect)Checks if request could be actually a client side route.static voidnoCache(jakarta.servlet.http.HttpServletResponse resp)Applies response header to prevent caching (because SPA page should not be cached).
-
-
-
Method Detail
-
isRootPage
public static boolean isRootPage(java.lang.String currentPath, java.lang.String rootPath)Note that root path is not the index page, but root mapping path, which will implicitly lead to index page.- Parameters:
currentPath- current pathrootPath- application root path- Returns:
- true if provided path is application root path, false otherwise
-
isHtmlRequest
public static boolean isHtmlRequest(jakarta.servlet.http.HttpServletRequest req)
Checks if provided request expects html response (by accept header). Did not consider wildcard type (*/*)) as html request, because browser request resources (like fonts) with such type. Only direct text/html type is recognized (assuming human request).- Parameters:
req- request instance- Returns:
- true if request expect html, false otherwise
-
isSpaRoute
public static boolean isSpaRoute(jakarta.servlet.http.HttpServletRequest req, java.util.regex.Pattern noRedirect)Checks if request could be actually a client side route. SPA route should be a html request (by accepted type) and not match to provided pattern (describing non-routing urls).- Parameters:
req- request instancenoRedirect- no-redirect pattern- Returns:
- true if request could be SPA route, false if not
-
noCache
public static void noCache(jakarta.servlet.http.HttpServletResponse resp)
Applies response header to prevent caching (because SPA page should not be cached).- Parameters:
resp- response instance
-
doRedirect
public static void doRedirect(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, java.lang.String target) throws java.io.IOException, jakarta.servlet.ServletExceptionPerform server redirect into root page. Means that current request considered as SPA route and server should return index page as response (under the same url) so client could handle url as internal navigation.No cache header is applied to response to prevent index page caching (by this route).
- Parameters:
req- request instanceres- response instancetarget- spa root path- Throws:
java.io.IOException- on errorjakarta.servlet.ServletException- on error
-
-