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:
emilnkrastev
2019-01-17 01:27:27 +02:00
committed by Spencer Gibb
parent 6d2929a289
commit dfc52c7ad1
2 changed files with 4 additions and 0 deletions

View File

@@ -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;
}
}
}

View File

@@ -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);