Don't run PreDecorationFilter if serviceId already set.

fixes gh-695
This commit is contained in:
Spencer Gibb
2016-03-02 18:25:52 -07:00
parent 8a2a608af0
commit 472b9d1757
2 changed files with 14 additions and 1 deletions

View File

@@ -58,7 +58,8 @@ public class PreDecorationFilter extends ZuulFilter {
@Override
public boolean shouldFilter() {
RequestContext ctx = RequestContext.getCurrentContext();
return !ctx.containsKey("forward.to");
return !ctx.containsKey("forward.to") // another filter has already forwarded
&& !ctx.containsKey("serviceId"); // another filter has already determined serviceId
}
@Override

View File

@@ -68,6 +68,18 @@ public class PreDecorationFilterTests {
assertEquals("pre", this.filter.filterType());
}
@Test
public void skippedIfServiceIdSet() throws Exception {
RequestContext.getCurrentContext().set("serviceId", "myservice");
assertEquals(false, this.filter.shouldFilter());
}
@Test
public void skippedIfForwardToSet() throws Exception {
RequestContext.getCurrentContext().set("forward.to", "mycontext");
assertEquals(false, this.filter.shouldFilter());
}
@Test
public void prefixRouteAddsHeader() throws Exception {
this.properties.setPrefix("/api");