Package com.vaadin.flow.server
Class HandlerHelper
java.lang.Object
com.vaadin.flow.server.HandlerHelper
- All Implemented Interfaces:
 Serializable
Contains helper methods for 
VaadinServlet and generally for handling
 VaadinRequests.- Since:
 - 1.0
 - See Also:
 
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumFramework internal enum for tracking the type of a request. - 
Method Summary
Modifier and TypeMethodDescriptionstatic LocalefindLocale(VaadinSession session, VaadinRequest request) Helper to find the most most suitable Locale.static StringgetCancelingRelativePath(String pathToCancel) Gets a relative path that cancels the provided path.getIconVariants(String iconPath) Gets the paths of the PWA icon variants for the given base icon.getPathIfInsideServlet(String servletMappingPath, String requestedPath) Returns the rest of the path after the servlet mapping part, if the requested path targets a path inside the servlet.static String[]URLs matching these patterns should be publicly available for applications to work.static String[]URLs matching these patterns should be publicly available for applications to work but might require a security context, i.e.static String[]URLs matching these patterns should be publicly available for applications to work.static StringgetRequestPathInsideContext(jakarta.servlet.http.HttpServletRequest request) Returns the requested path inside the context root.static booleanisFrameworkInternalRequest(String servletMappingPath, jakarta.servlet.http.HttpServletRequest request) Checks whether the request is an internal request.static booleanisNonHtmlInitiatedRequest(VaadinRequest request) Determines whether the given request is initiated by a non-HTML context.static booleanisNonHtmlInitiatedRequest(jakarta.servlet.http.HttpServletRequest request) Determines whether the given HTTP request is initiated by a non-HTML context.static booleanisPathUnsafe(String path) Checks if the given URL path contains the directory change instruction (dot-dot), taking into account possible double encoding in hexadecimal format, which can be injected maliciously.static booleanisRequestType(VaadinRequest request, HandlerHelper.RequestType requestType) Returns whether the given request is of the given type.static voidsetResponseNoCacheHeaders(BiConsumer<String, String> headerSetter, BiConsumer<String, Long> longHeaderSetter) Sets no cache headers to the specified response. 
- 
Method Details
- 
isRequestType
Returns whether the given request is of the given type.- Parameters:
 request- the request to checkrequestType- the type to check for- Returns:
 trueif the request is of the given type,falseotherwise
 - 
isFrameworkInternalRequest
public static boolean isFrameworkInternalRequest(String servletMappingPath, jakarta.servlet.http.HttpServletRequest request) Checks whether the request is an internal request. The requests listed inHandlerHelper.RequestTypeare considered internal as they are needed for applications to work.Requests for routes, static resources requests and similar are not considered internal requests.
- Parameters:
 servletMappingPath- the path the Vaadin servlet is mapped to, with or without and ending "/*"request- the servlet request- Returns:
 trueif the request is Vaadin internal,falseotherwise
 - 
getPathIfInsideServlet
public static Optional<String> getPathIfInsideServlet(String servletMappingPath, String requestedPath) Returns the rest of the path after the servlet mapping part, if the requested path targets a path inside the servlet.- Parameters:
 servletMappingPath- the servlet mapping from the servlet configurationrequestedPath- the request path relative to the context root- Returns:
 - an optional containing the path relative to the servlet if the request is inside the servlet mapping, an empty optional otherwise
 
 - 
getRequestPathInsideContext
Returns the requested path inside the context root.- Parameters:
 request- the servlet request- Returns:
 - the path inside the context root, not including the slash after the context root path
 
 - 
findLocale
Helper to find the most most suitable Locale. These potential sources are checked in order until a Locale is found:- The passed component (or UI) if not null
 UI.getCurrent()if defined- The passed session if not null
 VaadinSession.getCurrent()if defined- The passed request if not null
 VaadinService.getCurrentRequest()if definedLocale.getDefault()
- Parameters:
 session- the session that is searched for locale ornullif not availablerequest- the request that is searched for locale ornullif not available- Returns:
 - the found locale
 
 - 
setResponseNoCacheHeaders
public static void setResponseNoCacheHeaders(BiConsumer<String, String> headerSetter, BiConsumer<String, Long> longHeaderSetter) Sets no cache headers to the specified response.- Parameters:
 headerSetter- setter for string value headerslongHeaderSetter- setter for long value headers
 - 
getCancelingRelativePath
Gets a relative path that cancels the provided path. This essentially adds one .. for each part of the path to cancel.- Parameters:
 pathToCancel- the path that should be canceled- Returns:
 - a relative path that cancels out the provided path segment
 
 - 
isPathUnsafe
Checks if the given URL path contains the directory change instruction (dot-dot), taking into account possible double encoding in hexadecimal format, which can be injected maliciously.- Parameters:
 path- the URL path to be verified.- Returns:
 true, if the given path has a directory change instruction,falseotherwise.
 - 
getPublicResources
URLs matching these patterns should be publicly available for applications to work. Can be used for defining a bypass for rules in e.g. Spring Security.These paths are relative to a potential Vaadin mapping
 - 
getPublicResourcesRoot
URLs matching these patterns should be publicly available for applications to work. Can be used for defining a bypass for rules in e.g. Spring Security.These URLs are always relative to the root path and independent of any Vaadin mapping
 - 
getIconVariants
Gets the paths of the PWA icon variants for the given base icon.- Parameters:
 iconPath- path of the base icon.- Returns:
 - list of paths of icon variants.
 
 - 
getPublicResourcesRequiringSecurityContext
URLs matching these patterns should be publicly available for applications to work but might require a security context, i.e. authentication information. - 
isNonHtmlInitiatedRequest
public static boolean isNonHtmlInitiatedRequest(jakarta.servlet.http.HttpServletRequest request) Determines whether the given HTTP request is initiated by a non-HTML context. This is based on the value of the Sec-Fetch-Dest in the request headers. If the header value is absent or does not match certain predefined values, it is considered an HTML-initiated request. See Sec-Fetch-Dest header documentation for more details.- Parameters:
 request- the HTTP servlet request to evaluate- Returns:
 trueif the request is initiated by a non-HTML context;falseotherwise
 - 
isNonHtmlInitiatedRequest
Determines whether the given request is initiated by a non-HTML context. This is based on the value of the Sec-Fetch-Dest in the request headers. If the header value is absent or does not match certain predefined values, it is considered an HTML-initiated request. See Sec-Fetch-Dest header documentation for more details.- Parameters:
 request- the Vaadin request to evaluate- Returns:
 trueif the request is initiated by a non-HTML context;falseotherwise
 
 -