use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class HttpRequestMessageImplTest method getOriginalPort_respectsProxyProtocol.
@Test
public void getOriginalPort_respectsProxyProtocol() throws URISyntaxException {
SessionContext context = new SessionContext();
context.set(CommonContextKeys.PROXY_PROTOCOL_DESTINATION_ADDRESS, new InetSocketAddress(InetAddresses.forString("1.1.1.1"), 443));
Headers headers = new Headers();
headers.add("X-Forwarded-Port", "6000");
assertEquals(443, HttpRequestMessageImpl.getOriginalPort(context, headers, 9999));
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class HttpRequestMessageImplTest method testReconstructURI.
@Test
public void testReconstructURI() {
HttpQueryParams queryParams = new HttpQueryParams();
queryParams.add("flag", "5");
Headers headers = new Headers();
headers.add("Host", "blah.netflix.com");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals("https://blah.netflix.com:7002/some/where?flag=5", request.reconstructURI());
queryParams = new HttpQueryParams();
headers = new Headers();
headers.add("X-Forwarded-Host", "place.netflix.com");
headers.add("X-Forwarded-Port", "80");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "http", 7002, "localhost");
Assert.assertEquals("http://place.netflix.com/some/where", request.reconstructURI());
queryParams = new HttpQueryParams();
headers = new Headers();
headers.add("X-Forwarded-Host", "place.netflix.com");
headers.add("X-Forwarded-Proto", "https");
headers.add("X-Forwarded-Port", "443");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "http", 7002, "localhost");
Assert.assertEquals("https://place.netflix.com/some/where", request.reconstructURI());
queryParams = new HttpQueryParams();
headers = new Headers();
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "http", 7002, "localhost");
Assert.assertEquals("http://localhost:7002/some/where", request.reconstructURI());
queryParams = new HttpQueryParams();
queryParams.add("flag", "5");
queryParams.add("flag B", "9");
headers = new Headers();
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some%20where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals("https://localhost:7002/some%20where?flag=5&flag+B=9", request.reconstructURI());
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class HttpRequestMessageImplTest method testGetOriginalHost.
@Test
public void testGetOriginalHost() {
HttpQueryParams queryParams = new HttpQueryParams();
Headers headers = new Headers();
headers.add("Host", "blah.netflix.com");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals("blah.netflix.com", request.getOriginalHost());
queryParams = new HttpQueryParams();
headers = new Headers();
headers.add("Host", "0.0.0.1");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals("0.0.0.1", request.getOriginalHost());
queryParams = new HttpQueryParams();
headers = new Headers();
headers.add("Host", "0.0.0.1:2");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals("0.0.0.1", request.getOriginalHost());
queryParams = new HttpQueryParams();
headers = new Headers();
headers.add("Host", "[::2]");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals("[::2]", request.getOriginalHost());
queryParams = new HttpQueryParams();
headers = new Headers();
headers.add("Host", "[::2]:3");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals("[::2]", request.getOriginalHost());
headers = new Headers();
headers.add("Host", "blah.netflix.com");
headers.add("X-Forwarded-Host", "foo.netflix.com");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals("foo.netflix.com", request.getOriginalHost());
headers = new Headers();
headers.add("X-Forwarded-Host", "foo.netflix.com");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals("foo.netflix.com", request.getOriginalHost());
headers = new Headers();
headers.add("Host", "blah.netflix.com:8080");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
Assert.assertEquals("blah.netflix.com", request.getOriginalHost());
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class HttpRequestMessageImplTest method getOriginalHost_failsOnUnbracketedIpv6Address.
@Test
public void getOriginalHost_failsOnUnbracketedIpv6Address() {
HttpQueryParams queryParams = new HttpQueryParams();
Headers headers = new Headers();
headers.add("Host", "ba::dd");
request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost");
assertThrows(URISyntaxException.class, () -> HttpRequestMessageImpl.getOriginalHost(headers, "server"));
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class SurgicalDebugFilter method apply.
@Override
public HttpRequestMessage apply(HttpRequestMessage request) {
DynamicStringProperty routeVip = new DynamicStringProperty(ZuulConstants.ZUUL_DEBUG_VIP, null);
DynamicStringProperty routeHost = new DynamicStringProperty(ZuulConstants.ZUUL_DEBUG_HOST, null);
SessionContext ctx = request.getContext();
if (routeVip.get() != null || routeHost.get() != null) {
ctx.set("routeHost", routeHost.get());
ctx.set("routeVIP", routeVip.get());
request.getHeaders().set(ZuulHeaders.X_ZUUL_SURGICAL_FILTER, "true");
HttpQueryParams queryParams = request.getQueryParams();
queryParams.set("debugRequest", "true");
ctx.setDebugRequest(true);
ctx.set("zuulToZuul", true);
}
return request;
}
Aggregations