Search in sources :

Example 6 with Headers

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));
}
Also used : Headers(com.netflix.zuul.message.Headers) InetSocketAddress(java.net.InetSocketAddress) SessionContext(com.netflix.zuul.context.SessionContext) Test(org.junit.Test)

Example 7 with Headers

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));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Headers(com.netflix.zuul.message.Headers) SessionContext(com.netflix.zuul.context.SessionContext) Test(org.junit.Test)

Example 8 with Headers

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());
}
Also used : Headers(com.netflix.zuul.message.Headers) SessionContext(com.netflix.zuul.context.SessionContext) Test(org.junit.Test)

Example 9 with Headers

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());
}
Also used : Headers(com.netflix.zuul.message.Headers) SessionContext(com.netflix.zuul.context.SessionContext) Test(org.junit.Test)

Example 10 with Headers

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"));
}
Also used : Headers(com.netflix.zuul.message.Headers) SessionContext(com.netflix.zuul.context.SessionContext) Test(org.junit.Test)

Aggregations

Headers (com.netflix.zuul.message.Headers)26 SessionContext (com.netflix.zuul.context.SessionContext)17 Test (org.junit.Test)16 HttpResponseMessageImpl (com.netflix.zuul.message.http.HttpResponseMessageImpl)5 HttpQueryParams (com.netflix.zuul.message.http.HttpQueryParams)4 HttpResponseMessage (com.netflix.zuul.message.http.HttpResponseMessage)4 InetSocketAddress (java.net.InetSocketAddress)4 HttpRequestMessage (com.netflix.zuul.message.http.HttpRequestMessage)3 HttpRequestMessageImpl (com.netflix.zuul.message.http.HttpRequestMessageImpl)3 ZuulMessage (com.netflix.zuul.message.ZuulMessage)2 ZuulMessageImpl (com.netflix.zuul.message.ZuulMessageImpl)2 HttpRequestInfo (com.netflix.zuul.message.http.HttpRequestInfo)2 ByteBuf (io.netty.buffer.ByteBuf)2 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)2 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)2 SocketAddress (java.net.SocketAddress)2 Map (java.util.Map)2 Before (org.junit.Before)2 ClientException (com.netflix.client.ClientException)1 CompleteEvent (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent)1