Remove / from prefix if present.

Fixes #2625
This commit is contained in:
Ryan Baxter
2018-01-17 18:16:18 -05:00
committed by Spencer Gibb
parent a399cca7ce
commit c79ac8ba19
2 changed files with 12 additions and 0 deletions

View File

@@ -138,6 +138,9 @@ public class SimpleRouteLocator implements RouteLocator, Ordered {
}
String targetPath = path;
String prefix = this.properties.getPrefix();
if(prefix.endsWith("/")) {
prefix = prefix.substring(0, prefix.length() - 1);
}
if (path.startsWith(prefix + "/") && this.properties.isStripPrefix()) {
targetPath = path.substring(prefix.length());
}

View File

@@ -69,6 +69,15 @@ public class SimpleRouteLocatorTests {
assertEquals("/test/testservicea/**", locator.getRoutes().get(0).getFullPath());
}
@Test
public void testPrefix() {
ZuulProperties properties = new ZuulProperties();
properties.setPrefix("/test/");
RouteLocator locator = new FilteringRouteLocator("/", properties);
properties.getRoutes().put("testservicea", new ZuulRoute("/testservicea/**", "testservicea"));
assertEquals("/test/testservicea/**", locator.getRoutes().get(0).getFullPath());
}
@Test
public void test_getMatchingRouteFilterRouteAcceptor() {
RouteLocator locator = new FilteringRouteLocator("/", this.zuul);