Merge branch '5.1.x'

This commit is contained in:
Rossen Stoyanchev
2019-03-22 14:50:51 -04:00
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.
@@ -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());
}