Skip to content

Commit

Permalink
Clear ProducesRequestCondition cache attribute
Browse files Browse the repository at this point in the history
As of spring-projects/spring-framework#22644, Spring Framework caches
the "produces" condition when matching for endpoints in the
`HandlerMapping` infrastructure. This has been improved in
spring-projects/spring-framework#23091 to prevent side-effects in other
implementations.

Prior to this commit, the Spring Boot actuator infrastructure for
`EndpointHandlerMapping` would not clear the cached attribute,
presenting the same issue as Spring Framework's infrastructure. This
means that a custom arrangement with custom `HandlerMapping` or
`ContentTypeResolver` would not work properly and reuse the cached
produced conditions for other, unintented, parts of the handler mapping
process.

This commit clears the cached data and ensures that other handler
mapping implementations are free of that side-effect.

Fixes gh-20150
  • Loading branch information
bclozel committed Feb 17, 2020
1 parent bf8ed44 commit e59d3fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
return this.corsConfiguration;
}

@Override
public Mono<HandlerMethod> getHandlerInternal(ServerWebExchange exchange) {
return super.getHandlerInternal(exchange)
.doOnTerminate(() -> ProducesRequestCondition.clearMediaTypesAttribute(exchange));
}

@Override
protected boolean isHandler(Class<?> beanType) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
return this.corsConfiguration;
}

@Override
protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception {
try {
return super.getHandlerInternal(request);
}
finally {
ProducesRequestCondition.clearMediaTypesAttribute(request);
}
}

@Override
protected boolean isHandler(Class<?> beanType) {
return false;
Expand Down

0 comments on commit e59d3fb

Please sign in to comment.