use of com.netflix.zuul.message.Headers in project zuul by Netflix.
the class HttpRequestMessageImplTest method shouldPreferClientDestPortWhenInitialized.
@Test
public void shouldPreferClientDestPortWhenInitialized() {
HttpRequestMessageImpl message = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", new HttpQueryParams(), new Headers(), "192.168.0.2", "https", 7002, "localhost", new InetSocketAddress("api.netflix.com", 443), true);
assertEquals(message.getClientDestinationPort(), Optional.of(443));
}
use of com.netflix.zuul.message.Headers 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.message.Headers 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.message.Headers 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.message.Headers 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"));
}
Aggregations