Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ public EndpointServerWebExchangeMatcher excludingLinks() {

/**
* Restricts the matcher to only consider requests with a particular http method.
* <p>
* The links endpoint, if included, is always matched using {@code GET}.
* @param httpMethod the http method to include
* @return a copy of the matcher further restricted to only match requests with
* the specified http method
Expand Down Expand Up @@ -373,9 +375,9 @@ protected ServerWebExchangeMatcher createDelegate(WebEndpointProperties properti
String linksPath = getLinksPath(properties.getBasePath());
if (linksPath != null) {
List<ServerWebExchangeMatcher> linksMatchers = new ArrayList<>();
linksMatchers.add(new PathPatternParserServerWebExchangeMatcher(linksPath));
linksMatchers.add(new PathPatternParserServerWebExchangeMatcher(linksPath, HttpMethod.GET));
if (!linksPath.endsWith("/")) {
linksMatchers.add(new PathPatternParserServerWebExchangeMatcher(linksPath + "/"));
linksMatchers.add(new PathPatternParserServerWebExchangeMatcher(linksPath + "/", HttpMethod.GET));
}
return new OrServerWebExchangeMatcher(linksMatchers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ protected final List<RequestMatcher> getDelegateMatchers(RequestMatcherFactory r
protected List<RequestMatcher> getLinksMatchers(RequestMatcherFactory requestMatcherFactory,
RequestMatcherProvider matcherProvider, String linksPath) {
List<RequestMatcher> linksMatchers = new ArrayList<>();
linksMatchers.add(requestMatcherFactory.antPath(matcherProvider, null, linksPath));
linksMatchers.add(requestMatcherFactory.antPath(matcherProvider, HttpMethod.GET, linksPath));
if (!linksPath.endsWith("/")) {
linksMatchers.add(requestMatcherFactory.antPath(matcherProvider, null, linksPath, "/"));
linksMatchers.add(requestMatcherFactory.antPath(matcherProvider, HttpMethod.GET, linksPath, "/"));
}
return linksMatchers;
}
Expand Down Expand Up @@ -350,6 +350,8 @@ public EndpointRequestMatcher excludingLinks() {

/**
* Restricts the matcher to only consider requests with a particular HTTP method.
* <p>
* The links endpoint, if included, is always matched using {@code GET}.
* @param httpMethod the HTTP method to include
* @return a copy of the matcher further restricted to only match requests with
* the specified HTTP method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ void toAnyEndpointWithHttpMethodShouldRespectRequestMethod() {
assertMatcher(matcher, "/actuator").doesNotMatch(HttpMethod.GET, "/actuator/foo");
}

@Test
void toAnyEndpointWithHttpMethodShouldUseGetForLinks() {
ServerWebExchangeMatcher matcher = EndpointRequest.toAnyEndpoint().withHttpMethod(HttpMethod.POST);
assertMatcher(matcher, "/actuator").matches(HttpMethod.GET, "/actuator");
assertMatcher(matcher, "/actuator").doesNotMatch(HttpMethod.POST, "/actuator");
assertMatcher(matcher, "/actuator").matches(HttpMethod.GET, "/actuator/");
assertMatcher(matcher, "/actuator").doesNotMatch(HttpMethod.POST, "/actuator/");
}

@Test
void toAnyEndpointShouldMatchEndpointPathWithTrailingSlash() {
ServerWebExchangeMatcher matcher = EndpointRequest.toAnyEndpoint();
Expand Down Expand Up @@ -140,8 +149,10 @@ void toLinksShouldOnlyMatchLinks() {
ServerWebExchangeMatcher matcher = EndpointRequest.toLinks();
assertMatcher(matcher).doesNotMatch("/actuator/foo");
assertMatcher(matcher).doesNotMatch("/actuator/bar");
assertMatcher(matcher).matches("/actuator");
assertMatcher(matcher).matches("/actuator/");
assertMatcher(matcher).matches(HttpMethod.GET, "/actuator");
assertMatcher(matcher).doesNotMatch(HttpMethod.POST, "/actuator");
assertMatcher(matcher).matches(HttpMethod.GET, "/actuator/");
assertMatcher(matcher).doesNotMatch(HttpMethod.POST, "/actuator/");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void toAnyEndpointShouldMatchEndpointPath() {
assertMatcher(matcher, "/actuator").matches("/actuator/foo/zoo/");
assertMatcher(matcher, "/actuator").matches("/actuator/bar");
assertMatcher(matcher, "/actuator").matches("/actuator/bar/baz");
assertMatcher(matcher, "/actuator").matches("/actuator");
assertMatcher(matcher, "/actuator").matches(HttpMethod.GET, "/actuator");
}

@Test
Expand All @@ -75,12 +75,22 @@ void toAnyEndpointWithHttpMethodShouldRespectRequestMethod() {
assertMatcher(matcher, "/actuator").doesNotMatch(HttpMethod.GET, "/actuator/foo");
}

@Test
void toAnyEndpointWithHttpMethodShouldUseGetForLinks() {
EndpointRequest.EndpointRequestMatcher matcher = EndpointRequest.toAnyEndpoint()
.withHttpMethod(HttpMethod.POST);
assertMatcher(matcher, "/actuator").matches(HttpMethod.GET, "/actuator");
assertMatcher(matcher, "/actuator").doesNotMatch(HttpMethod.POST, "/actuator");
assertMatcher(matcher, "/actuator").matches(HttpMethod.GET, "/actuator/");
assertMatcher(matcher, "/actuator").doesNotMatch(HttpMethod.POST, "/actuator/");
}

@Test
void toAnyEndpointShouldMatchEndpointPathWithTrailingSlash() {
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
assertMatcher(matcher, "/actuator").matches("/actuator/foo/");
assertMatcher(matcher, "/actuator").matches("/actuator/bar/");
assertMatcher(matcher, "/actuator").matches("/actuator/");
assertMatcher(matcher, "/actuator").matches(HttpMethod.GET, "/actuator/");
}

@Test
Expand All @@ -97,7 +107,7 @@ void toAnyEndpointWhenBasePathIsEmptyAndManagementPortDifferentShouldMatchLinks(
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
RequestMatcherAssert assertMatcher = assertMatcher(matcher, mockPathMappedEndpoints(""), null,
WebServerNamespace.MANAGEMENT);
assertMatcher.matches("/");
assertMatcher.matches(HttpMethod.GET, "/");
assertMatcher.matches("/foo");
}

Expand All @@ -112,7 +122,7 @@ void toAnyEndpointWhenDispatcherServletPathProviderNotAvailableUsesEmptyPath() {
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
assertMatcher(matcher, "/actuator").matches("/actuator/foo");
assertMatcher(matcher, "/actuator").matches("/actuator/bar");
assertMatcher(matcher, "/actuator").matches("/actuator");
assertMatcher(matcher, "/actuator").matches(HttpMethod.GET, "/actuator");
assertMatcher(matcher, "/actuator").doesNotMatch("/actuator/baz");
}

Expand Down Expand Up @@ -147,8 +157,10 @@ void toLinksShouldOnlyMatchLinks() {
RequestMatcher matcher = EndpointRequest.toLinks();
assertMatcher(matcher).doesNotMatch("/actuator/foo");
assertMatcher(matcher).doesNotMatch("/actuator/bar");
assertMatcher(matcher).matches("/actuator");
assertMatcher(matcher).matches("/actuator/");
assertMatcher(matcher).matches(HttpMethod.GET, "/actuator");
assertMatcher(matcher).doesNotMatch(HttpMethod.POST, "/actuator");
assertMatcher(matcher).matches(HttpMethod.GET, "/actuator/");
assertMatcher(matcher).doesNotMatch(HttpMethod.POST, "/actuator/");
}

@Test
Expand All @@ -165,7 +177,7 @@ void toLinksWhenBasePathEmptyAndManagementPortDifferentShouldMatchRoot() {
RequestMatcher matcher = EndpointRequest.toLinks();
RequestMatcherAssert assertMatcher = assertMatcher(matcher, mockPathMappedEndpoints(""), null,
WebServerNamespace.MANAGEMENT);
assertMatcher.matches("/");
assertMatcher.matches(HttpMethod.GET, "/");
assertMatcher.doesNotMatch("/foo");
}

Expand All @@ -180,7 +192,7 @@ void excludeByClassShouldNotMatchExcluded() {
assertMatcher(matcher, pathMappedEndpoints).doesNotMatch("/actuator/foo");
assertMatcher(matcher, pathMappedEndpoints).doesNotMatch("/actuator/baz");
assertMatcher(matcher).matches("/actuator/bar");
assertMatcher(matcher).matches("/actuator");
assertMatcher(matcher).matches(HttpMethod.GET, "/actuator");
}

@Test
Expand All @@ -195,7 +207,7 @@ void excludeByIdShouldNotMatchExcluded() {
RequestMatcher matcher = EndpointRequest.toAnyEndpoint().excluding("foo");
assertMatcher(matcher).doesNotMatch("/actuator/foo");
assertMatcher(matcher).matches("/actuator/bar");
assertMatcher(matcher).matches("/actuator");
assertMatcher(matcher).matches(HttpMethod.GET, "/actuator");
}

@Test
Expand Down
Loading