Merge branch '5.1.x'

This commit is contained in:
Rossen Stoyanchev 2019-03-22 14:50:51 -04:00
commit f8121515bf
7 changed files with 65 additions and 40 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -40,10 +40,15 @@ class ReadOnlyHttpHeaders extends HttpHeaders {
@Nullable
private MediaType cachedContentType;
@Nullable
private List<MediaType> cachedAccept;
ReadOnlyHttpHeaders(HttpHeaders headers) {
super(headers.headers);
}
@Override
public MediaType getContentType() {
if (this.cachedContentType != null) {
@ -56,6 +61,18 @@ class ReadOnlyHttpHeaders extends HttpHeaders {
}
}
@Override
public List<MediaType> getAccept() {
if (this.cachedAccept != null) {
return this.cachedAccept;
}
else {
List<MediaType> accept = super.getAccept();
this.cachedAccept = accept;
return accept;
}
}
@Override
public List<String> get(Object key) {
List<String> values = this.headers.get(key);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -43,7 +43,7 @@ import org.springframework.web.server.UnsupportedMediaTypeStatusException;
*/
public final class ConsumesRequestCondition extends AbstractRequestCondition<ConsumesRequestCondition> {
private static final ConsumesRequestCondition PRE_FLIGHT_MATCH = new ConsumesRequestCondition();
private static final ConsumesRequestCondition EMPTY_CONDITION = new ConsumesRequestCondition();
private final List<ConsumeMediaTypeExpression> expressions;
@ -161,7 +161,7 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition<Con
@Override
public ConsumesRequestCondition getMatchingCondition(ServerWebExchange exchange) {
if (CorsUtils.isPreFlightRequest(exchange.getRequest())) {
return PRE_FLIGHT_MATCH;
return EMPTY_CONDITION;
}
if (isEmpty()) {
return this;

View File

@ -47,8 +47,6 @@ import org.springframework.web.server.UnsupportedMediaTypeStatusException;
*/
public final class ProducesRequestCondition extends AbstractRequestCondition<ProducesRequestCondition> {
private static final ProducesRequestCondition PRE_FLIGHT_MATCH = new ProducesRequestCondition();
private static final ProducesRequestCondition EMPTY_CONDITION = new ProducesRequestCondition();
@ -187,11 +185,8 @@ public final class ProducesRequestCondition extends AbstractRequestCondition<Pro
@Override
@Nullable
public ProducesRequestCondition getMatchingCondition(ServerWebExchange exchange) {
if (CorsUtils.isPreFlightRequest(exchange.getRequest())) {
return PRE_FLIGHT_MATCH;
}
if (isEmpty()) {
return this;
if (isEmpty() || CorsUtils.isPreFlightRequest(exchange.getRequest())) {
return EMPTY_CONDITION;
}
Set<ProduceMediaTypeExpression> result = new LinkedHashSet<>(this.expressions);
result.removeIf(expression -> !expression.match(exchange));

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -216,25 +216,34 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
@Nullable
public RequestMappingInfo getMatchingCondition(ServerWebExchange exchange) {
RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(exchange);
ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(exchange);
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 (methods == null) {
return null;
}
ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(exchange);
if (params == null) {
return null;
}
HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(exchange);
if (headers == null) {
return null;
}
// Match "Content-Type" and "Accept" (parsed ones and cached) before patterns
ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(exchange);
if (consumes == null) {
return null;
}
ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(exchange);
if (produces == null) {
return null;
}
PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(exchange);
if (patterns == null) {
return null;
}
RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(exchange);
if (custom == null) {
return null;
}
return new RequestMappingInfo(this.name, patterns,
methods, params, headers, consumes, produces, custom.getCondition());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -46,7 +46,7 @@ import org.springframework.web.servlet.mvc.condition.HeadersRequestCondition.Hea
*/
public final class ConsumesRequestCondition extends AbstractRequestCondition<ConsumesRequestCondition> {
private static final ConsumesRequestCondition PRE_FLIGHT_MATCH = new ConsumesRequestCondition();
private static final ConsumesRequestCondition EMPTY_CONDITION = new ConsumesRequestCondition();
private final List<ConsumeMediaTypeExpression> expressions;
@ -163,7 +163,7 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition<Con
@Nullable
public ConsumesRequestCondition getMatchingCondition(HttpServletRequest request) {
if (CorsUtils.isPreFlightRequest(request)) {
return PRE_FLIGHT_MATCH;
return EMPTY_CONDITION;
}
if (isEmpty()) {
return this;

View File

@ -47,8 +47,6 @@ import org.springframework.web.servlet.mvc.condition.HeadersRequestCondition.Hea
*/
public final class ProducesRequestCondition extends AbstractRequestCondition<ProducesRequestCondition> {
private static final ProducesRequestCondition PRE_FLIGHT_MATCH = new ProducesRequestCondition();
private static final ProducesRequestCondition EMPTY_CONDITION = new ProducesRequestCondition();
private static final List<ProduceMediaTypeExpression> MEDIA_TYPE_ALL_LIST =
@ -187,11 +185,8 @@ public final class ProducesRequestCondition extends AbstractRequestCondition<Pro
@Override
@Nullable
public ProducesRequestCondition getMatchingCondition(HttpServletRequest request) {
if (CorsUtils.isPreFlightRequest(request)) {
return PRE_FLIGHT_MATCH;
}
if (isEmpty()) {
return this;
if (isEmpty() || CorsUtils.isPreFlightRequest(request)) {
return EMPTY_CONDITION;
}
List<MediaType> acceptedMediaTypes;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -217,20 +217,29 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
@Nullable
public RequestMappingInfo getMatchingCondition(HttpServletRequest request) {
RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request);
ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request);
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 (methods == null) {
return null;
}
ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request);
if (params == null) {
return null;
}
HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(request);
if (headers == 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;
}
PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(request);
if (patterns == null) {
return null;
}
RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(request);
if (custom == null) {
return null;