diff --git a/spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java b/spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java index 341938f1ba2a..6fe96f081960 100644 --- a/spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java @@ -40,6 +40,9 @@ class ReadOnlyHttpHeaders extends HttpHeaders { @Nullable private MediaType cachedContentType; + @Nullable + private MediaType cachedAccept; + ReadOnlyHttpHeaders(HttpHeaders headers) { super(headers.headers); } @@ -56,6 +59,18 @@ public MediaType getContentType() { } } + @Override + public List getAccept() { + if (this.cachedAccept != null) { + return this.cachedAccept; + } + else { + List accept = super.getAccept(); + this.cachedAccept = accept; + return accept; + } + } + @Override public List get(Object key) { List values = this.headers.get(key); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java index 795dc53185de..479fcbed15c5 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java @@ -216,20 +216,29 @@ else if (this.name != null) { @Nullable public RequestMappingInfo getMatchingCondition(ServerWebExchange exchange) { RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(exchange); + if (methods == null) { + return null; + } ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(exchange); + if (params == null) { + return null; + } HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(exchange); - ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(exchange); - ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(exchange); - - if (methods == null || params == null || headers == null || consumes == null || produces == null) { + if (headers == null) { return null; } - PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(exchange); if (patterns == null) { return null; } - + ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(exchange); + if (consumes == null) { + return null; + } + ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(exchange); + if (produces == null) { + return null; + } RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(exchange); if (custom == null) { return null; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java index 29a1d6382553..537af70221c8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java @@ -217,20 +217,29 @@ else if (this.name != null) { @Nullable public RequestMappingInfo getMatchingCondition(HttpServletRequest request) { RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request); + if (methods == null) { + return null; + } ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request); + if (params == null) { + return null; + } HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(request); - ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request); - ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request); - - if (methods == null || params == null || headers == null || consumes == null || produces == null) { + if (headers == null) { return null; } - PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(request); if (patterns == null) { return null; } - + ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request); + if (consumes == null) { + return null; + } + ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request); + if (produces == null) { + return null; + } RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(request); if (custom == null) { return null;