File tree Expand file tree Collapse file tree 4 files changed +43
-0
lines changed
spring-webflux/src/main/java/org/springframework/web/reactive/result
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc Expand file tree Collapse file tree 4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -320,6 +320,17 @@ private List<ProduceMediaTypeExpression> getExpressionsToCompare() {
320320 }
321321
322322
323+ /**
324+ * Use this to clear {@link #MEDIA_TYPES_ATTRIBUTE} that contains the parsed,
325+ * requested media types.
326+ * @param exchange the current exchange
327+ * @since 5.2
328+ */
329+ public static void clearMediaTypesAttribute (ServerWebExchange exchange ) {
330+ exchange .getAttributes ().remove (MEDIA_TYPES_ATTRIBUTE );
331+ }
332+
333+
323334 /**
324335 * Parses and matches a single media type expression to a request's 'Accept' header.
325336 */
Original file line number Diff line number Diff line change 2424import java .util .Map ;
2525import java .util .function .Predicate ;
2626
27+ import reactor .core .publisher .Mono ;
28+
2729import org .springframework .context .EmbeddedValueResolverAware ;
2830import org .springframework .core .annotation .AnnotatedElementUtils ;
2931import org .springframework .core .annotation .MergedAnnotation ;
4345import org .springframework .web .reactive .accept .RequestedContentTypeResolver ;
4446import org .springframework .web .reactive .accept .RequestedContentTypeResolverBuilder ;
4547import org .springframework .web .reactive .result .condition .ConsumesRequestCondition ;
48+ import org .springframework .web .reactive .result .condition .ProducesRequestCondition ;
4649import org .springframework .web .reactive .result .condition .RequestCondition ;
4750import org .springframework .web .reactive .result .method .RequestMappingInfo ;
4851import org .springframework .web .reactive .result .method .RequestMappingInfoHandlerMapping ;
52+ import org .springframework .web .server .ServerWebExchange ;
4953
5054/**
5155 * An extension of {@link RequestMappingInfoHandlerMapping} that creates
@@ -352,4 +356,10 @@ private String resolveCorsAnnotationValue(String value) {
352356 }
353357 }
354358
359+ @ Override
360+ public Mono <HandlerMethod > getHandlerInternal (ServerWebExchange exchange ) {
361+ return super .getHandlerInternal (exchange )
362+ .doOnTerminate (() -> ProducesRequestCondition .clearMediaTypesAttribute (exchange ));
363+ }
364+
355365}
Original file line number Diff line number Diff line change @@ -326,6 +326,17 @@ private List<ProduceMediaTypeExpression> getExpressionsToCompare() {
326326 }
327327
328328
329+ /**
330+ * Use this to clear {@link #MEDIA_TYPES_ATTRIBUTE} that contains the parsed,
331+ * requested media types.
332+ * @param request the current request
333+ * @since 5.2
334+ */
335+ public static void clearMediaTypesAttribute (HttpServletRequest request ) {
336+ request .removeAttribute (MEDIA_TYPES_ATTRIBUTE );
337+ }
338+
339+
329340 /**
330341 * Parses and matches a single media type expression to a request's 'Accept' header.
331342 */
Original file line number Diff line number Diff line change 4848import org .springframework .web .servlet .mvc .condition .AbstractRequestCondition ;
4949import org .springframework .web .servlet .mvc .condition .CompositeRequestCondition ;
5050import org .springframework .web .servlet .mvc .condition .ConsumesRequestCondition ;
51+ import org .springframework .web .servlet .mvc .condition .ProducesRequestCondition ;
5152import org .springframework .web .servlet .mvc .condition .RequestCondition ;
5253import org .springframework .web .servlet .mvc .method .RequestMappingInfo ;
5354import org .springframework .web .servlet .mvc .method .RequestMappingInfoHandlerMapping ;
@@ -441,4 +442,14 @@ private String resolveCorsAnnotationValue(String value) {
441442 }
442443 }
443444
445+ @ Override
446+ protected HandlerMethod getHandlerInternal (HttpServletRequest request ) throws Exception {
447+ try {
448+ return super .getHandlerInternal (request );
449+ }
450+ finally {
451+ ProducesRequestCondition .clearMediaTypesAttribute (request );
452+ }
453+ }
454+
444455}
You can’t perform that action at this time.
0 commit comments