Skip to content

Commit e59d3fb

Browse files
committed
Clear ProducesRequestCondition cache attribute
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
1 parent bf8ed44 commit e59d3fb

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java

+6
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
198198
return this.corsConfiguration;
199199
}
200200

201+
@Override
202+
public Mono<HandlerMethod> getHandlerInternal(ServerWebExchange exchange) {
203+
return super.getHandlerInternal(exchange)
204+
.doOnTerminate(() -> ProducesRequestCondition.clearMediaTypesAttribute(exchange));
205+
}
206+
201207
@Override
202208
protected boolean isHandler(Class<?> beanType) {
203209
return false;

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java

+10
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
231231
return this.corsConfiguration;
232232
}
233233

234+
@Override
235+
protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception {
236+
try {
237+
return super.getHandlerInternal(request);
238+
}
239+
finally {
240+
ProducesRequestCondition.clearMediaTypesAttribute(request);
241+
}
242+
}
243+
234244
@Override
235245
protected boolean isHandler(Class<?> beanType) {
236246
return false;

0 commit comments

Comments
 (0)