mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Revisit EndpointRequest matcher for additional paths
Prior to this commit, the `EndpointRequest` request matcher generator would create many, complex matchers for the case of health groups exposed on additional paths. This commit revisits the matcher generation and simplifies their matching to avoid conflicts with other matchers. Fixes gh-49648
This commit is contained in:
+3
-3
@@ -441,12 +441,12 @@ public final class EndpointRequest {
|
||||
|
||||
@Override
|
||||
protected ServerWebExchangeMatcher createDelegate(PathMappedEndpoints endpoints) {
|
||||
Set<String> paths = this.endpoints.stream()
|
||||
List<ServerWebExchangeMatcher> delegateMatchers = this.endpoints.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(this::getEndpointId)
|
||||
.flatMap((endpointId) -> streamAdditionalPaths(endpoints, endpointId))
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
List<ServerWebExchangeMatcher> delegateMatchers = getDelegateMatchers(paths, this.httpMethod);
|
||||
.map(PathPatternParserServerWebExchangeMatcher::new)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
return (!CollectionUtils.isEmpty(delegateMatchers)) ? new OrServerWebExchangeMatcher(delegateMatchers)
|
||||
: EMPTY_MATCHER;
|
||||
}
|
||||
|
||||
+3
-4
@@ -475,13 +475,12 @@ public final class EndpointRequest {
|
||||
RequestMatcherFactory requestMatcherFactory) {
|
||||
PathMappedEndpoints endpoints = context.getBean(PathMappedEndpoints.class);
|
||||
RequestMatcherProvider matcherProvider = getRequestMatcherProvider(context);
|
||||
Set<String> paths = this.endpoints.stream()
|
||||
List<RequestMatcher> delegateMatchers = this.endpoints.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(this::getEndpointId)
|
||||
.flatMap((endpointId) -> streamAdditionalPaths(endpoints, endpointId))
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
List<RequestMatcher> delegateMatchers = getDelegateMatchers(requestMatcherFactory, matcherProvider, paths,
|
||||
this.httpMethod);
|
||||
.map((path) -> requestMatcherFactory.antPath(matcherProvider, this.httpMethod, path))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
return (!CollectionUtils.isEmpty(delegateMatchers)) ? new OrRequestMatcher(delegateMatchers)
|
||||
: EMPTY_MATCHER;
|
||||
}
|
||||
|
||||
+1
@@ -315,6 +315,7 @@ class EndpointRequestTests {
|
||||
FooEndpoint.class);
|
||||
RequestMatcherAssert assertMatcher = assertMatcher(matcher, new PathMappedEndpoints("",
|
||||
() -> List.of(mockEndpoint(EndpointId.of("foo"), "test", WebServerNamespace.SERVER, "/additional"))));
|
||||
assertMatcher.doesNotMatch("/additional/foo");
|
||||
assertMatcher.doesNotMatch("/foo");
|
||||
assertMatcher.doesNotMatch("/bar");
|
||||
}
|
||||
|
||||
+1
@@ -321,6 +321,7 @@ class EndpointRequestTests {
|
||||
FooEndpoint.class);
|
||||
RequestMatcherAssert assertMatcher = assertMatcher(matcher, new PathMappedEndpoints("",
|
||||
() -> List.of(mockEndpoint(EndpointId.of("foo"), "test", WebServerNamespace.SERVER, "/additional"))));
|
||||
assertMatcher.doesNotMatch("/additional/foo");
|
||||
assertMatcher.doesNotMatch("/foo");
|
||||
assertMatcher.doesNotMatch("/bar");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user