|
|
@ -164,6 +164,86 @@ public class PreDecorationFilterTests { |
|
|
|
getHeader(ctx.getOriginResponseHeaders(), "x-zuul-serviceid")); |
|
|
|
getHeader(ctx.getOriginResponseHeaders(), "x-zuul-serviceid")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void routeWithContextPath() { |
|
|
|
|
|
|
|
this.properties.setStripPrefix(false); |
|
|
|
|
|
|
|
this.request.setRequestURI("/api/foo/1"); |
|
|
|
|
|
|
|
this.request.setContextPath("/context-path"); |
|
|
|
|
|
|
|
this.routeLocator.addRoute( |
|
|
|
|
|
|
|
new ZuulRoute("foo", "/api/foo/**", "foo", null, false, null, null)); |
|
|
|
|
|
|
|
this.filter.run(); |
|
|
|
|
|
|
|
RequestContext ctx = RequestContext.getCurrentContext(); |
|
|
|
|
|
|
|
assertEquals("/api/foo/1", ctx.get("requestURI")); |
|
|
|
|
|
|
|
assertEquals("localhost", ctx.getZuulRequestHeaders().get("x-forwarded-host")); |
|
|
|
|
|
|
|
assertEquals("80", ctx.getZuulRequestHeaders().get("x-forwarded-port")); |
|
|
|
|
|
|
|
assertEquals("http", ctx.getZuulRequestHeaders().get("x-forwarded-proto")); |
|
|
|
|
|
|
|
assertEquals("/context-path", |
|
|
|
|
|
|
|
ctx.getZuulRequestHeaders().get("x-forwarded-prefix")); |
|
|
|
|
|
|
|
assertEquals("foo", |
|
|
|
|
|
|
|
getHeader(ctx.getOriginResponseHeaders(), "x-zuul-serviceid")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void prefixRouteWithContextPath() { |
|
|
|
|
|
|
|
this.properties.setPrefix("/api"); |
|
|
|
|
|
|
|
this.properties.setStripPrefix(true); |
|
|
|
|
|
|
|
this.request.setRequestURI("/api/foo/1"); |
|
|
|
|
|
|
|
this.request.setContextPath("/context-path"); |
|
|
|
|
|
|
|
this.routeLocator.addRoute( |
|
|
|
|
|
|
|
new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null)); |
|
|
|
|
|
|
|
this.filter.run(); |
|
|
|
|
|
|
|
RequestContext ctx = RequestContext.getCurrentContext(); |
|
|
|
|
|
|
|
assertEquals("/foo/1", ctx.get("requestURI")); |
|
|
|
|
|
|
|
assertEquals("localhost", ctx.getZuulRequestHeaders().get("x-forwarded-host")); |
|
|
|
|
|
|
|
assertEquals("80", ctx.getZuulRequestHeaders().get("x-forwarded-port")); |
|
|
|
|
|
|
|
assertEquals("http", ctx.getZuulRequestHeaders().get("x-forwarded-proto")); |
|
|
|
|
|
|
|
assertEquals("/context-path/api", |
|
|
|
|
|
|
|
ctx.getZuulRequestHeaders().get("x-forwarded-prefix")); |
|
|
|
|
|
|
|
assertEquals("foo", |
|
|
|
|
|
|
|
getHeader(ctx.getOriginResponseHeaders(), "x-zuul-serviceid")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void routeIgnoreContextPathIfPrefixHeader() { |
|
|
|
|
|
|
|
this.properties.setStripPrefix(false); |
|
|
|
|
|
|
|
this.request.setRequestURI("/api/foo/1"); |
|
|
|
|
|
|
|
this.request.setContextPath("/context-path"); |
|
|
|
|
|
|
|
this.request.addHeader("X-Forwarded-Prefix", "/prefix"); |
|
|
|
|
|
|
|
this.routeLocator.addRoute( |
|
|
|
|
|
|
|
new ZuulRoute("foo", "/api/foo/**", "foo", null, false, null, null)); |
|
|
|
|
|
|
|
this.filter.run(); |
|
|
|
|
|
|
|
RequestContext ctx = RequestContext.getCurrentContext(); |
|
|
|
|
|
|
|
assertEquals("/api/foo/1", ctx.get("requestURI")); |
|
|
|
|
|
|
|
assertEquals("localhost", ctx.getZuulRequestHeaders().get("x-forwarded-host")); |
|
|
|
|
|
|
|
assertEquals("80", ctx.getZuulRequestHeaders().get("x-forwarded-port")); |
|
|
|
|
|
|
|
assertEquals("http", ctx.getZuulRequestHeaders().get("x-forwarded-proto")); |
|
|
|
|
|
|
|
assertEquals("/prefix", |
|
|
|
|
|
|
|
ctx.getZuulRequestHeaders().get("x-forwarded-prefix")); |
|
|
|
|
|
|
|
assertEquals("foo", |
|
|
|
|
|
|
|
getHeader(ctx.getOriginResponseHeaders(), "x-zuul-serviceid")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void prefixRouteIgnoreContextPathIfPrefixHeader() { |
|
|
|
|
|
|
|
this.properties.setPrefix("/api"); |
|
|
|
|
|
|
|
this.properties.setStripPrefix(true); |
|
|
|
|
|
|
|
this.request.setRequestURI("/api/foo/1"); |
|
|
|
|
|
|
|
this.request.setContextPath("/context-path"); |
|
|
|
|
|
|
|
this.request.addHeader("X-Forwarded-Prefix", "/prefix"); |
|
|
|
|
|
|
|
this.routeLocator.addRoute( |
|
|
|
|
|
|
|
new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null)); |
|
|
|
|
|
|
|
this.filter.run(); |
|
|
|
|
|
|
|
RequestContext ctx = RequestContext.getCurrentContext(); |
|
|
|
|
|
|
|
assertEquals("/foo/1", ctx.get("requestURI")); |
|
|
|
|
|
|
|
assertEquals("localhost", ctx.getZuulRequestHeaders().get("x-forwarded-host")); |
|
|
|
|
|
|
|
assertEquals("80", ctx.getZuulRequestHeaders().get("x-forwarded-port")); |
|
|
|
|
|
|
|
assertEquals("http", ctx.getZuulRequestHeaders().get("x-forwarded-proto")); |
|
|
|
|
|
|
|
assertEquals("/prefix/api", |
|
|
|
|
|
|
|
ctx.getZuulRequestHeaders().get("x-forwarded-prefix")); |
|
|
|
|
|
|
|
assertEquals("foo", |
|
|
|
|
|
|
|
getHeader(ctx.getOriginResponseHeaders(), "x-zuul-serviceid")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void forwardRouteAddsLocation() throws Exception { |
|
|
|
public void forwardRouteAddsLocation() throws Exception { |
|
|
|
this.properties.setPrefix("/api"); |
|
|
|
this.properties.setPrefix("/api"); |
|
|
|