Browse Source

Remove / from prefix if present.

Fixes #2625
pull/6/head
Ryan Baxter 7 years ago committed by Spencer Gibb
parent
commit
c79ac8ba19
  1. 3
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocator.java
  2. 9
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocatorTests.java

3
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocator.java

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

9
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocatorTests.java

@ -69,6 +69,15 @@ public class SimpleRouteLocatorTests {
assertEquals("/test/testservicea/**", locator.getRoutes().get(0).getFullPath()); 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 @Test
public void test_getMatchingRouteFilterRouteAcceptor() { public void test_getMatchingRouteFilterRouteAcceptor() {
RouteLocator locator = new FilteringRouteLocator("/", this.zuul); RouteLocator locator = new FilteringRouteLocator("/", this.zuul);

Loading…
Cancel
Save