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:
Arjen Poutsma
2020-09-03 15:10:36 +02:00
parent 88249b2d9a
commit d550d344d5
14 changed files with 122 additions and 137 deletions

View File

@@ -249,7 +249,7 @@ public class PathPattern implements Comparable<PathPattern> {
@Nullable
public PathRemainingMatchInfo matchStartOfPath(PathContainer pathContainer) {
if (this.head == null) {
return new PathRemainingMatchInfo(pathContainer);
return new PathRemainingMatchInfo(EMPTY_PATH, pathContainer);
}
else if (!hasLength(pathContainer)) {
return null;
@@ -262,15 +262,17 @@ public class PathPattern implements Comparable<PathPattern> {
return null;
}
else {
PathRemainingMatchInfo info;
PathContainer pathMatched;
PathContainer pathRemaining;
if (matchingContext.remainingPathIndex == pathContainer.elements().size()) {
info = new PathRemainingMatchInfo(EMPTY_PATH, matchingContext.getPathMatchResult());
pathMatched = pathContainer;
pathRemaining = EMPTY_PATH;
}
else {
info = new PathRemainingMatchInfo(pathContainer.subPath(matchingContext.remainingPathIndex),
matchingContext.getPathMatchResult());
pathMatched = pathContainer.subPath(0, matchingContext.remainingPathIndex);
pathRemaining = pathContainer.subPath(matchingContext.remainingPathIndex);
}
return info;
return new PathRemainingMatchInfo(pathMatched, pathRemaining, matchingContext.getPathMatchResult());
}
}
@@ -592,20 +594,32 @@ public class PathPattern implements Comparable<PathPattern> {
*/
public static class PathRemainingMatchInfo {
private final PathContainer pathMatched;
private final PathContainer pathRemaining;
private final PathMatchInfo pathMatchInfo;
PathRemainingMatchInfo(PathContainer pathRemaining) {
this(pathRemaining, PathMatchInfo.EMPTY);
PathRemainingMatchInfo(PathContainer pathMatched, PathContainer pathRemaining) {
this(pathMatched, pathRemaining, PathMatchInfo.EMPTY);
}
PathRemainingMatchInfo(PathContainer pathRemaining, PathMatchInfo pathMatchInfo) {
PathRemainingMatchInfo(PathContainer pathMatched, PathContainer pathRemaining,
PathMatchInfo pathMatchInfo) {
this.pathRemaining = pathRemaining;
this.pathMatched = pathMatched;
this.pathMatchInfo = pathMatchInfo;
}
/**
* Return the part of a path that was matched by a pattern.
* @since 5.3
*/
public PathContainer getPathMatched() {
return this.pathMatched;
}
/**
* Return the part of a path that was not matched by a pattern.
*/