Make use of HttpServletMapping when available #25100
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: enhancement
A general enhancement
Milestone
UrlPathHelper
determines the portion of the path to use for application mappings which is the path after the contextPath and after a servletPath prefix.The determination of the servletPath prefix is difficult and inherently fragile. It depends on the Servlet mapping type, which is not known at runtime (prior to Servlet 4.0). Furthermore, the servletPath is decoded and normalized while the full path requestURI is neither, so the
requestURI
must be decoded to be comparable but that can result in additional/
or;
which can change the path, and so can normalizations by Servlet containers.One way out is to set
alwaysUseFullPath=true
onUrlPathHelper
which only deals with the contextPath and that's fine for the most common, default Servlet mapping `"/". It's only the Servlet mapping by path prefix that requires a determination of the Servlet path but that's less common and historic.In Servlet 4.0, the request exposes HttpServletMapping with details about the current mapping including the Servlet mapping pattern, the mapping type, and the part of the URL that matched. This does not solve the issues with determining the path after the servletPath, but knowing the mapping type can help to avoid looking for a servletPath prefix where there is none. Effectively for all mapping types except
MappingMatch.PATH
we can process as ifalwaysUseFullPath=true
.The text was updated successfully, but these errors were encountered: