Skip to content

Commit c9a86e1

Browse files
committed
Polish
See gh-22598
1 parent d10174a commit c9a86e1

File tree

7 files changed

+25
-33
lines changed

7 files changed

+25
-33
lines changed

spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,12 +41,14 @@ class ReadOnlyHttpHeaders extends HttpHeaders {
4141
private MediaType cachedContentType;
4242

4343
@Nullable
44-
private MediaType cachedAccept;
44+
private List<MediaType> cachedAccept;
45+
4546

4647
ReadOnlyHttpHeaders(HttpHeaders headers) {
4748
super(headers.headers);
4849
}
4950

51+
5052
@Override
5153
public MediaType getContentType() {
5254
if (this.cachedContentType != null) {

spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@
4343
*/
4444
public final class ConsumesRequestCondition extends AbstractRequestCondition<ConsumesRequestCondition> {
4545

46-
private static final ConsumesRequestCondition PRE_FLIGHT_MATCH = new ConsumesRequestCondition();
46+
private static final ConsumesRequestCondition EMPTY_CONDITION = new ConsumesRequestCondition();
4747

4848

4949
private final List<ConsumeMediaTypeExpression> expressions;
@@ -161,7 +161,7 @@ public ConsumesRequestCondition combine(ConsumesRequestCondition other) {
161161
@Override
162162
public ConsumesRequestCondition getMatchingCondition(ServerWebExchange exchange) {
163163
if (CorsUtils.isPreFlightRequest(exchange.getRequest())) {
164-
return PRE_FLIGHT_MATCH;
164+
return EMPTY_CONDITION;
165165
}
166166
if (isEmpty()) {
167167
return this;

spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
*/
4848
public final class ProducesRequestCondition extends AbstractRequestCondition<ProducesRequestCondition> {
4949

50-
private static final ProducesRequestCondition PRE_FLIGHT_MATCH = new ProducesRequestCondition();
51-
5250
private static final ProducesRequestCondition EMPTY_CONDITION = new ProducesRequestCondition();
5351

5452

@@ -187,11 +185,8 @@ public ProducesRequestCondition combine(ProducesRequestCondition other) {
187185
@Override
188186
@Nullable
189187
public ProducesRequestCondition getMatchingCondition(ServerWebExchange exchange) {
190-
if (CorsUtils.isPreFlightRequest(exchange.getRequest())) {
191-
return PRE_FLIGHT_MATCH;
192-
}
193-
if (isEmpty()) {
194-
return this;
188+
if (isEmpty() || CorsUtils.isPreFlightRequest(exchange.getRequest())) {
189+
return EMPTY_CONDITION;
195190
}
196191
Set<ProduceMediaTypeExpression> result = new LinkedHashSet<>(this.expressions);
197192
result.removeIf(expression -> !expression.match(exchange));

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -227,10 +227,7 @@ public RequestMappingInfo getMatchingCondition(ServerWebExchange exchange) {
227227
if (headers == null) {
228228
return null;
229229
}
230-
PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(exchange);
231-
if (patterns == null) {
232-
return null;
233-
}
230+
// Match "Content-Type" and "Accept" (parsed ones and cached) before patterns
234231
ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(exchange);
235232
if (consumes == null) {
236233
return null;
@@ -239,11 +236,14 @@ public RequestMappingInfo getMatchingCondition(ServerWebExchange exchange) {
239236
if (produces == null) {
240237
return null;
241238
}
239+
PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(exchange);
240+
if (patterns == null) {
241+
return null;
242+
}
242243
RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(exchange);
243244
if (custom == null) {
244245
return null;
245246
}
246-
247247
return new RequestMappingInfo(this.name, patterns,
248248
methods, params, headers, consumes, produces, custom.getCondition());
249249
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@
4646
*/
4747
public final class ConsumesRequestCondition extends AbstractRequestCondition<ConsumesRequestCondition> {
4848

49-
private static final ConsumesRequestCondition PRE_FLIGHT_MATCH = new ConsumesRequestCondition();
49+
private static final ConsumesRequestCondition EMPTY_CONDITION = new ConsumesRequestCondition();
5050

5151
private final List<ConsumeMediaTypeExpression> expressions;
5252

@@ -163,7 +163,7 @@ public ConsumesRequestCondition combine(ConsumesRequestCondition other) {
163163
@Nullable
164164
public ConsumesRequestCondition getMatchingCondition(HttpServletRequest request) {
165165
if (CorsUtils.isPreFlightRequest(request)) {
166-
return PRE_FLIGHT_MATCH;
166+
return EMPTY_CONDITION;
167167
}
168168
if (isEmpty()) {
169169
return this;

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
*/
4848
public final class ProducesRequestCondition extends AbstractRequestCondition<ProducesRequestCondition> {
4949

50-
private static final ProducesRequestCondition PRE_FLIGHT_MATCH = new ProducesRequestCondition();
51-
5250
private static final ProducesRequestCondition EMPTY_CONDITION = new ProducesRequestCondition();
5351

5452
private static final List<ProduceMediaTypeExpression> MEDIA_TYPE_ALL_LIST =
@@ -187,11 +185,8 @@ public ProducesRequestCondition combine(ProducesRequestCondition other) {
187185
@Override
188186
@Nullable
189187
public ProducesRequestCondition getMatchingCondition(HttpServletRequest request) {
190-
if (CorsUtils.isPreFlightRequest(request)) {
191-
return PRE_FLIGHT_MATCH;
192-
}
193-
if (isEmpty()) {
194-
return this;
188+
if (isEmpty() || CorsUtils.isPreFlightRequest(request)) {
189+
return EMPTY_CONDITION;
195190
}
196191

197192
List<MediaType> acceptedMediaTypes;

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -228,10 +228,6 @@ public RequestMappingInfo getMatchingCondition(HttpServletRequest request) {
228228
if (headers == null) {
229229
return null;
230230
}
231-
PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(request);
232-
if (patterns == null) {
233-
return null;
234-
}
235231
ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request);
236232
if (consumes == null) {
237233
return null;
@@ -240,6 +236,10 @@ public RequestMappingInfo getMatchingCondition(HttpServletRequest request) {
240236
if (produces == null) {
241237
return null;
242238
}
239+
PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(request);
240+
if (patterns == null) {
241+
return null;
242+
}
243243
RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(request);
244244
if (custom == null) {
245245
return null;

0 commit comments

Comments
 (0)