Skip to content

Commit

Permalink
Minor updates in HandlerMappingIntrospector
Browse files Browse the repository at this point in the history
Required by Spring Security to complete work on
spring-projects/spring-security#14128

The setCache and resetCache methods used from createCacheFilter are now
public. Generally they don't need to be used outside of the Filter if
only making checks against the current request. Spring Security, however,
makes additional checks against requests with alternative paths.
  • Loading branch information
rstoyanchev committed Dec 12, 2023
1 parent 1e742aa commit db52c77
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,12 @@ public List<HandlerMapping> getHandlerMappings() {
public Filter createCacheFilter() {
return (request, response, chain) -> {
CachedResult previous = setCache((HttpServletRequest) request);
chain.doFilter(request, response);
resetCache(request, previous);
try {
chain.doFilter(request, response);
}
finally {
resetCache(request, previous);
}
};
}

Expand All @@ -206,7 +210,7 @@ public Filter createCacheFilter() {
* @since 6.0.14
*/
@Nullable
private CachedResult setCache(HttpServletRequest request) {
public CachedResult setCache(HttpServletRequest request) {
CachedResult previous = (CachedResult) request.getAttribute(CACHED_RESULT_ATTRIBUTE);
if (previous == null || !previous.matches(request)) {
HttpServletRequest wrapped = new AttributesPreservingRequest(request);
Expand Down Expand Up @@ -245,7 +249,7 @@ private CachedResult setCache(HttpServletRequest request) {
* a filter after delegating to the rest of the chain.
* @since 6.0.14
*/
private void resetCache(ServletRequest request, @Nullable CachedResult cachedResult) {
public void resetCache(ServletRequest request, @Nullable CachedResult cachedResult) {
request.setAttribute(CACHED_RESULT_ATTRIBUTE, cachedResult);
}

Expand Down Expand Up @@ -363,7 +367,7 @@ private <T> T doWithHandlerMapping(
* @since 6.0.14
*/
@SuppressWarnings("serial")
private static final class CachedResult {
public static final class CachedResult {

private final DispatcherType dispatcherType;

Expand Down

0 comments on commit db52c77

Please sign in to comment.