Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make use of HttpServletMapping when available #25100

Closed
rstoyanchev opened this issue May 19, 2020 · 0 comments
Closed

Make use of HttpServletMapping when available #25100

rstoyanchev opened this issue May 19, 2020 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

rstoyanchev commented May 19, 2020

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 on UrlPathHelper 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 if alwaysUseFullPath=true.

@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels May 19, 2020
@rstoyanchev rstoyanchev added this to the 5.3 M1 milestone May 19, 2020
@rstoyanchev rstoyanchev self-assigned this May 19, 2020
rstoyanchev added a commit that referenced this issue May 19, 2020
In many places UrlPathHelper is created and used without any
customizations, in some cases repeatedly. This commit adds a
shared read-only UrlPathHelper instance with default settings.

See gh-25100
kenny5he pushed a commit to kenny5he/spring-framework that referenced this issue Jun 21, 2020
In many places UrlPathHelper is created and used without any
customizations, in some cases repeatedly. This commit adds a
shared read-only UrlPathHelper instance with default settings.

See spring-projectsgh-25100
kenny5he pushed a commit to kenny5he/spring-framework that referenced this issue Jun 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant