Respect context path in WebMvc.fn & WebFlux.fn
This commit makes several changes in both WebMvc.fn as well as WebFlux.fn. - ServerRequest now exposes a RequestPath through requestPath(), and pathContainer() has been deprecated. - The PathPredicate and PathResourceLookupFunction now respects this RequestPath's pathInApplication() in their path-related functionality. - When nesting, the PathPredicate now appends the matched part of the path to the current context path, instead of removing the matched part (which was done previously). This has the same result: the matched part is gone, but now the full path stays the same. Closes gh-25270
This commit is contained in:
@@ -29,7 +29,6 @@ import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRe
|
||||
import org.springframework.web.testfixture.server.MockServerWebExchange;
|
||||
import org.springframework.web.util.pattern.PathPatternParser;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
@@ -141,7 +140,7 @@ public class RequestPredicatesTests {
|
||||
URI uri = URI.create("https://localhost/path");
|
||||
RequestPredicate predicate = RequestPredicates.path("/p*");
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get(uri.toString()).build();
|
||||
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), emptyList());
|
||||
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
||||
assertThat(predicate.test(request)).isTrue();
|
||||
|
||||
mockRequest = MockServerHttpRequest.head("https://example.com").build();
|
||||
@@ -178,6 +177,15 @@ public class RequestPredicatesTests {
|
||||
assertThat(predicate.test(request)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathWithContext() {
|
||||
RequestPredicate predicate = RequestPredicates.path("/p*");
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://localhost/context/path")
|
||||
.contextPath("/context").build();
|
||||
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
|
||||
assertThat(predicate.test(request)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headers() {
|
||||
String name = "MyHeader";
|
||||
|
||||
Reference in New Issue
Block a user