Merge branch '5.2.x'
This commit is contained in:
commit
a7f8120164
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2018 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -50,7 +50,7 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource
|
||||||
* @since 5.0.6
|
* @since 5.0.6
|
||||||
*/
|
*/
|
||||||
public UrlBasedCorsConfigurationSource() {
|
public UrlBasedCorsConfigurationSource() {
|
||||||
this(new PathPatternParser());
|
this(PathPatternParser.defaultInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -112,4 +112,35 @@ public class PathPatternParser {
|
||||||
return new InternalPathPatternParser(this).parse(pathPattern);
|
return new InternalPathPatternParser(this).parse(pathPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared, read-only instance of {@code PathPatternParser}. Uses default settings:
|
||||||
|
* <ul>
|
||||||
|
* <li>{@code matchOptionalTrailingSeparator=true}
|
||||||
|
* <li>{@code caseSensitivetrue}
|
||||||
|
* <li>{@code pathOptions=PathContainer.Options.HTTP_PATH}
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
public final static PathPatternParser defaultInstance = new PathPatternParser() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMatchOptionalTrailingSeparator(boolean matchOptionalTrailingSeparator) {
|
||||||
|
raiseError();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCaseSensitive(boolean caseSensitive) {
|
||||||
|
raiseError();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPathOptions(PathContainer.Options pathOptions) {
|
||||||
|
raiseError();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void raiseError() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is a read-only, shared instance that cannot be modified");
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2018 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -41,8 +41,6 @@ import org.springframework.web.util.pattern.PathPatternParser;
|
||||||
*/
|
*/
|
||||||
class PathResourceLookupFunction implements Function<ServerRequest, Mono<Resource>> {
|
class PathResourceLookupFunction implements Function<ServerRequest, Mono<Resource>> {
|
||||||
|
|
||||||
private static final PathPatternParser PATTERN_PARSER = new PathPatternParser();
|
|
||||||
|
|
||||||
private final PathPattern pattern;
|
private final PathPattern pattern;
|
||||||
|
|
||||||
private final Resource location;
|
private final Resource location;
|
||||||
|
|
@ -51,7 +49,7 @@ class PathResourceLookupFunction implements Function<ServerRequest, Mono<Resourc
|
||||||
public PathResourceLookupFunction(String pattern, Resource location) {
|
public PathResourceLookupFunction(String pattern, Resource location) {
|
||||||
Assert.hasLength(pattern, "'pattern' must not be empty");
|
Assert.hasLength(pattern, "'pattern' must not be empty");
|
||||||
Assert.notNull(location, "'location' must not be null");
|
Assert.notNull(location, "'location' must not be null");
|
||||||
this.pattern = PATTERN_PARSER.parse(pattern);
|
this.pattern = PathPatternParser.defaultInstance.parse(pattern);
|
||||||
this.location = location;
|
this.location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,9 +72,6 @@ public abstract class RequestPredicates {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(RequestPredicates.class);
|
private static final Log logger = LogFactory.getLog(RequestPredicates.class);
|
||||||
|
|
||||||
private static final PathPatternParser DEFAULT_PATTERN_PARSER = new PathPatternParser();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a {@code RequestPredicate} that always matches.
|
* Return a {@code RequestPredicate} that always matches.
|
||||||
* @return a predicate that always matches
|
* @return a predicate that always matches
|
||||||
|
|
@ -115,7 +112,7 @@ public abstract class RequestPredicates {
|
||||||
if (!pattern.isEmpty() && !pattern.startsWith("/")) {
|
if (!pattern.isEmpty() && !pattern.startsWith("/")) {
|
||||||
pattern = "/" + pattern;
|
pattern = "/" + pattern;
|
||||||
}
|
}
|
||||||
return pathPredicates(DEFAULT_PATTERN_PARSER).apply(pattern);
|
return pathPredicates(PathPatternParser.defaultInstance).apply(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2018 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -54,8 +54,6 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
||||||
private static final Log logger = LogFactory.getLog(ResourceUrlProvider.class);
|
private static final Log logger = LogFactory.getLog(ResourceUrlProvider.class);
|
||||||
|
|
||||||
|
|
||||||
private final PathPatternParser patternParser = new PathPatternParser();
|
|
||||||
|
|
||||||
private final Map<PathPattern, ResourceWebHandler> handlerMap = new LinkedHashMap<>();
|
private final Map<PathPattern, ResourceWebHandler> handlerMap = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -78,7 +76,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
||||||
this.handlerMap.clear();
|
this.handlerMap.clear();
|
||||||
handlerMap.forEach((rawPattern, resourceWebHandler) -> {
|
handlerMap.forEach((rawPattern, resourceWebHandler) -> {
|
||||||
rawPattern = prependLeadingSlash(rawPattern);
|
rawPattern = prependLeadingSlash(rawPattern);
|
||||||
PathPattern pattern = this.patternParser.parse(rawPattern);
|
PathPattern pattern = PathPatternParser.defaultInstance.parse(rawPattern);
|
||||||
this.handlerMap.put(pattern, resourceWebHandler);
|
this.handlerMap.put(pattern, resourceWebHandler);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ import org.springframework.web.util.pattern.PathPatternParser;
|
||||||
public final class PatternsRequestCondition extends AbstractRequestCondition<PatternsRequestCondition> {
|
public final class PatternsRequestCondition extends AbstractRequestCondition<PatternsRequestCondition> {
|
||||||
|
|
||||||
private static final SortedSet<PathPattern> EMPTY_PATH_PATTERN =
|
private static final SortedSet<PathPattern> EMPTY_PATH_PATTERN =
|
||||||
new TreeSet<>(Collections.singleton(new PathPatternParser().parse("")));
|
new TreeSet<>(Collections.singleton(PathPatternParser.defaultInstance.parse("")));
|
||||||
|
|
||||||
|
|
||||||
private final SortedSet<PathPattern> patterns;
|
private final SortedSet<PathPattern> patterns;
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,8 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||||
|
|
||||||
private final RequestConditionHolder customConditionHolder;
|
private final RequestConditionHolder customConditionHolder;
|
||||||
|
|
||||||
|
private final int hashCode;
|
||||||
|
|
||||||
|
|
||||||
public RequestMappingInfo(@Nullable String name, @Nullable PatternsRequestCondition patterns,
|
public RequestMappingInfo(@Nullable String name, @Nullable PatternsRequestCondition patterns,
|
||||||
@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
|
@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
|
||||||
|
|
@ -101,6 +103,10 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||||
this.consumesCondition = (consumes != null ? consumes : EMPTY_CONSUMES);
|
this.consumesCondition = (consumes != null ? consumes : EMPTY_CONSUMES);
|
||||||
this.producesCondition = (produces != null ? produces : EMPTY_PRODUCES);
|
this.producesCondition = (produces != null ? produces : EMPTY_PRODUCES);
|
||||||
this.customConditionHolder = (custom != null ? new RequestConditionHolder(custom) : EMPTY_CUSTOM);
|
this.customConditionHolder = (custom != null ? new RequestConditionHolder(custom) : EMPTY_CUSTOM);
|
||||||
|
|
||||||
|
this.hashCode = calculateHashCode(
|
||||||
|
this.patternsCondition, this.methodsCondition, this.paramsCondition, this.headersCondition,
|
||||||
|
this.consumesCondition, this.producesCondition, this.customConditionHolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -323,10 +329,17 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (this.patternsCondition.hashCode() * 31 + // primary differentiation
|
return this.hashCode;
|
||||||
this.methodsCondition.hashCode() + this.paramsCondition.hashCode() +
|
}
|
||||||
this.headersCondition.hashCode() + this.consumesCondition.hashCode() +
|
|
||||||
this.producesCondition.hashCode() + this.customConditionHolder.hashCode());
|
private static int calculateHashCode(
|
||||||
|
PatternsRequestCondition patterns, RequestMethodsRequestCondition methods,
|
||||||
|
ParamsRequestCondition params, HeadersRequestCondition headers,
|
||||||
|
ConsumesRequestCondition consumes, ProducesRequestCondition produces,
|
||||||
|
RequestConditionHolder custom) {
|
||||||
|
|
||||||
|
return patterns.hashCode() * 31 + methods.hashCode() + params.hashCode() +
|
||||||
|
headers.hashCode() + consumes.hashCode() + produces.hashCode() + custom.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -527,7 +540,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||||
public RequestMappingInfo build() {
|
public RequestMappingInfo build() {
|
||||||
|
|
||||||
PathPatternParser parser = (this.options.getPatternParser() != null ?
|
PathPatternParser parser = (this.options.getPatternParser() != null ?
|
||||||
this.options.getPatternParser() : new PathPatternParser());
|
this.options.getPatternParser() : PathPatternParser.defaultInstance);
|
||||||
|
|
||||||
RequestedContentTypeResolver contentTypeResolver = this.options.getContentTypeResolver();
|
RequestedContentTypeResolver contentTypeResolver = this.options.getContentTypeResolver();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -40,8 +40,6 @@ import org.springframework.web.util.pattern.PathPatternParser;
|
||||||
*/
|
*/
|
||||||
class PathResourceLookupFunction implements Function<ServerRequest, Optional<Resource>> {
|
class PathResourceLookupFunction implements Function<ServerRequest, Optional<Resource>> {
|
||||||
|
|
||||||
private static final PathPatternParser PATTERN_PARSER = new PathPatternParser();
|
|
||||||
|
|
||||||
private final PathPattern pattern;
|
private final PathPattern pattern;
|
||||||
|
|
||||||
private final Resource location;
|
private final Resource location;
|
||||||
|
|
@ -50,7 +48,7 @@ class PathResourceLookupFunction implements Function<ServerRequest, Optional<Res
|
||||||
public PathResourceLookupFunction(String pattern, Resource location) {
|
public PathResourceLookupFunction(String pattern, Resource location) {
|
||||||
Assert.hasLength(pattern, "'pattern' must not be empty");
|
Assert.hasLength(pattern, "'pattern' must not be empty");
|
||||||
Assert.notNull(location, "'location' must not be null");
|
Assert.notNull(location, "'location' must not be null");
|
||||||
this.pattern = PATTERN_PARSER.parse(pattern);
|
this.pattern = PathPatternParser.defaultInstance.parse(pattern);
|
||||||
this.location = location;
|
this.location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,9 +72,6 @@ public abstract class RequestPredicates {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(RequestPredicates.class);
|
private static final Log logger = LogFactory.getLog(RequestPredicates.class);
|
||||||
|
|
||||||
private static final PathPatternParser DEFAULT_PATTERN_PARSER = new PathPatternParser();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a {@code RequestPredicate} that always matches.
|
* Return a {@code RequestPredicate} that always matches.
|
||||||
* @return a predicate that always matches
|
* @return a predicate that always matches
|
||||||
|
|
@ -114,7 +111,7 @@ public abstract class RequestPredicates {
|
||||||
if (!pattern.isEmpty() && !pattern.startsWith("/")) {
|
if (!pattern.isEmpty() && !pattern.startsWith("/")) {
|
||||||
pattern = "/" + pattern;
|
pattern = "/" + pattern;
|
||||||
}
|
}
|
||||||
return pathPredicates(DEFAULT_PATTERN_PARSER).apply(pattern);
|
return pathPredicates(PathPatternParser.defaultInstance).apply(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,6 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||||
private static final RequestConditionHolder EMPTY_CUSTOM = new RequestConditionHolder(null);
|
private static final RequestConditionHolder EMPTY_CUSTOM = new RequestConditionHolder(null);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
|
@ -90,6 +89,8 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||||
|
|
||||||
private final RequestConditionHolder customConditionHolder;
|
private final RequestConditionHolder customConditionHolder;
|
||||||
|
|
||||||
|
private final int hashCode;
|
||||||
|
|
||||||
|
|
||||||
public RequestMappingInfo(@Nullable String name, @Nullable PatternsRequestCondition patterns,
|
public RequestMappingInfo(@Nullable String name, @Nullable PatternsRequestCondition patterns,
|
||||||
@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
|
@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
|
||||||
|
|
@ -104,6 +105,10 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||||
this.consumesCondition = (consumes != null ? consumes : EMPTY_CONSUMES);
|
this.consumesCondition = (consumes != null ? consumes : EMPTY_CONSUMES);
|
||||||
this.producesCondition = (produces != null ? produces : EMPTY_PRODUCES);
|
this.producesCondition = (produces != null ? produces : EMPTY_PRODUCES);
|
||||||
this.customConditionHolder = (custom != null ? new RequestConditionHolder(custom) : EMPTY_CUSTOM);
|
this.customConditionHolder = (custom != null ? new RequestConditionHolder(custom) : EMPTY_CUSTOM);
|
||||||
|
|
||||||
|
this.hashCode = calculateHashCode(
|
||||||
|
this.patternsCondition, this.methodsCondition, this.paramsCondition, this.headersCondition,
|
||||||
|
this.consumesCondition, this.producesCondition, this.customConditionHolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -125,7 +130,6 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||||
info.consumesCondition, info.producesCondition, customRequestCondition);
|
info.consumesCondition, info.producesCondition, customRequestCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the name for this mapping, or {@code null}.
|
* Return the name for this mapping, or {@code null}.
|
||||||
*/
|
*/
|
||||||
|
|
@ -336,10 +340,17 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (this.patternsCondition.hashCode() * 31 + // primary differentiation
|
return this.hashCode;
|
||||||
this.methodsCondition.hashCode() + this.paramsCondition.hashCode() +
|
}
|
||||||
this.headersCondition.hashCode() + this.consumesCondition.hashCode() +
|
|
||||||
this.producesCondition.hashCode() + this.customConditionHolder.hashCode());
|
private static int calculateHashCode(
|
||||||
|
PatternsRequestCondition patterns, RequestMethodsRequestCondition methods,
|
||||||
|
ParamsRequestCondition params, HeadersRequestCondition headers,
|
||||||
|
ConsumesRequestCondition consumes, ProducesRequestCondition produces,
|
||||||
|
RequestConditionHolder custom) {
|
||||||
|
|
||||||
|
return patterns.hashCode() * 31 + methods.hashCode() + params.hashCode() +
|
||||||
|
headers.hashCode() + consumes.hashCode() + produces.hashCode() + custom.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue