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
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() {
320
320
}
321
321
322
322
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
+
323
334
/**
324
335
* Parses and matches a single media type expression to a request's 'Accept' header.
325
336
*/
Original file line number Diff line number Diff line change 24
24
import java .util .Map ;
25
25
import java .util .function .Predicate ;
26
26
27
+ import reactor .core .publisher .Mono ;
28
+
27
29
import org .springframework .context .EmbeddedValueResolverAware ;
28
30
import org .springframework .core .annotation .AnnotatedElementUtils ;
29
31
import org .springframework .core .annotation .MergedAnnotation ;
43
45
import org .springframework .web .reactive .accept .RequestedContentTypeResolver ;
44
46
import org .springframework .web .reactive .accept .RequestedContentTypeResolverBuilder ;
45
47
import org .springframework .web .reactive .result .condition .ConsumesRequestCondition ;
48
+ import org .springframework .web .reactive .result .condition .ProducesRequestCondition ;
46
49
import org .springframework .web .reactive .result .condition .RequestCondition ;
47
50
import org .springframework .web .reactive .result .method .RequestMappingInfo ;
48
51
import org .springframework .web .reactive .result .method .RequestMappingInfoHandlerMapping ;
52
+ import org .springframework .web .server .ServerWebExchange ;
49
53
50
54
/**
51
55
* An extension of {@link RequestMappingInfoHandlerMapping} that creates
@@ -352,4 +356,10 @@ private String resolveCorsAnnotationValue(String value) {
352
356
}
353
357
}
354
358
359
+ @ Override
360
+ public Mono <HandlerMethod > getHandlerInternal (ServerWebExchange exchange ) {
361
+ return super .getHandlerInternal (exchange )
362
+ .doOnTerminate (() -> ProducesRequestCondition .clearMediaTypesAttribute (exchange ));
363
+ }
364
+
355
365
}
Original file line number Diff line number Diff line change @@ -326,6 +326,17 @@ private List<ProduceMediaTypeExpression> getExpressionsToCompare() {
326
326
}
327
327
328
328
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
+
329
340
/**
330
341
* Parses and matches a single media type expression to a request's 'Accept' header.
331
342
*/
Original file line number Diff line number Diff line change 48
48
import org .springframework .web .servlet .mvc .condition .AbstractRequestCondition ;
49
49
import org .springframework .web .servlet .mvc .condition .CompositeRequestCondition ;
50
50
import org .springframework .web .servlet .mvc .condition .ConsumesRequestCondition ;
51
+ import org .springframework .web .servlet .mvc .condition .ProducesRequestCondition ;
51
52
import org .springframework .web .servlet .mvc .condition .RequestCondition ;
52
53
import org .springframework .web .servlet .mvc .method .RequestMappingInfo ;
53
54
import org .springframework .web .servlet .mvc .method .RequestMappingInfoHandlerMapping ;
@@ -441,4 +442,14 @@ private String resolveCorsAnnotationValue(String value) {
441
442
}
442
443
}
443
444
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
+
444
455
}
You can’t perform that action at this time.
0 commit comments