Fix trailing slash in strip prefix filter (#770)
The existing Strip Prefix filter removes the trailing slash, which causes incoming requests to fail upon hitting the downstream service.
This commit is contained in:
committed by
Spencer Gibb
parent
6d2929a289
commit
dfc52c7ad1
@@ -53,6 +53,7 @@ public class StripPrefixGatewayFilterFactory extends AbstractGatewayFilterFactor
|
||||
String path = request.getURI().getRawPath();
|
||||
String newPath = "/" + Arrays.stream(StringUtils.tokenizeToStringArray(path, "/"))
|
||||
.skip(config.parts).collect(Collectors.joining("/"));
|
||||
newPath += (newPath.length() > 1 && path.endsWith("/") ? "/" : "");
|
||||
ServerHttpRequest newRequest = request.mutate()
|
||||
.path(newPath)
|
||||
.build();
|
||||
@@ -74,4 +75,5 @@ public class StripPrefixGatewayFilterFactory extends AbstractGatewayFilterFactor
|
||||
this.parts = parts;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@ public class StripPrefixGatewayFilterFactoryTests {
|
||||
testStripPrefixFilter("/foo/bar", "/bar", 1);
|
||||
testStripPrefixFilter("/foo/bar", "/", 2);
|
||||
testStripPrefixFilter("/foo/bar", "/foo/bar", 0);
|
||||
testStripPrefixFilter("/foo/bar/", "/", 2);
|
||||
testStripPrefixFilter("/foo/bar/", "/foo/bar/", 0);
|
||||
testStripPrefixFilter("", "/", 1);
|
||||
testStripPrefixFilter("/", "/", 1);
|
||||
testStripPrefixFilter("/", "/", 2);
|
||||
|
||||
Reference in New Issue
Block a user