Unverified Commit a2e1836e by Spencer Gibb

Merge pull request #1656 from sbley/master

* pull1656: Separate adding X-ForwardedProto header
parents 601e2204 53649f60
...@@ -184,6 +184,8 @@ public class PreDecorationFilter extends ZuulFilter { ...@@ -184,6 +184,8 @@ public class PreDecorationFilter extends ZuulFilter {
} else { } else {
port = request.getHeader("X-Forwarded-Port") + "," + port; port = request.getHeader("X-Forwarded-Port") + "," + port;
} }
}
if (hasHeader(request, "X-Forwarded-Proto")) {
proto = request.getHeader("X-Forwarded-Proto") + "," + proto; proto = request.getHeader("X-Forwarded-Proto") + "," + proto;
} }
ctx.addZuulRequestHeader("X-Forwarded-Host", host); ctx.addZuulRequestHeader("X-Forwarded-Host", host);
......
...@@ -104,7 +104,7 @@ public class PreDecorationFilterTests { ...@@ -104,7 +104,7 @@ public class PreDecorationFilterTests {
} }
@Test @Test
public void xForwardedHostAppends() throws Exception { public void xForwardedHostAndProtoAppend() throws Exception {
this.properties.setPrefix("/api"); this.properties.setPrefix("/api");
this.request.setRequestURI("/api/foo/1"); this.request.setRequestURI("/api/foo/1");
this.request.setRemoteAddr("5.6.7.8"); this.request.setRemoteAddr("5.6.7.8");
...@@ -121,6 +121,39 @@ public class PreDecorationFilterTests { ...@@ -121,6 +121,39 @@ public class PreDecorationFilterTests {
} }
@Test @Test
public void xForwardedHostOnlyAppends() throws Exception {
this.properties.setPrefix("/api");
this.request.setRequestURI("/api/foo/1");
this.request.setRemoteAddr("5.6.7.8");
this.request.setServerPort(8080);
this.request.addHeader("X-Forwarded-Host", "example.com");
this.routeLocator.addRoute(
new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null));
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
assertEquals("example.com,localhost:8080",
ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("8080", ctx.getZuulRequestHeaders().get("x-forwarded-port"));
assertEquals("http", ctx.getZuulRequestHeaders().get("x-forwarded-proto"));
}
@Test
public void xForwardedProtoOnlyAppends() throws Exception {
this.properties.setPrefix("/api");
this.request.setRequestURI("/api/foo/1");
this.request.setRemoteAddr("5.6.7.8");
this.request.setServerPort(8080);
this.request.addHeader("X-Forwarded-Proto", "https");
this.routeLocator.addRoute(
new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null));
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
assertEquals("localhost:8080", ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("8080", ctx.getZuulRequestHeaders().get("x-forwarded-port"));
assertEquals("https,http", ctx.getZuulRequestHeaders().get("x-forwarded-proto"));
}
@Test
public void hostHeaderSet() throws Exception { public void hostHeaderSet() throws Exception {
this.properties.setPrefix("/api"); this.properties.setPrefix("/api");
this.properties.setAddHostHeader(true); this.properties.setAddHostHeader(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment