Search in sources :

Example 16 with SessionContext

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

Example 17 with SessionContext

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

Example 18 with SessionContext

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

Example 19 with SessionContext

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

Example 20 with SessionContext

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;
}
Also used : HttpQueryParams(com.netflix.zuul.message.http.HttpQueryParams) DynamicStringProperty(com.netflix.config.DynamicStringProperty) SessionContext(com.netflix.zuul.context.SessionContext)

Aggregations

SessionContext (com.netflix.zuul.context.SessionContext)43 Test (org.junit.Test)23 Headers (com.netflix.zuul.message.Headers)16 HttpRequestMessage (com.netflix.zuul.message.http.HttpRequestMessage)6 HttpResponseMessage (com.netflix.zuul.message.http.HttpResponseMessage)5 HttpResponseMessageImpl (com.netflix.zuul.message.http.HttpResponseMessageImpl)5 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)5 HttpQueryParams (com.netflix.zuul.message.http.HttpQueryParams)4 InetSocketAddress (java.net.InetSocketAddress)4 ClientException (com.netflix.client.ClientException)3 ZuulException (com.netflix.zuul.exception.ZuulException)3 HttpRequestMessageImpl (com.netflix.zuul.message.http.HttpRequestMessageImpl)3 StatusCategory (com.netflix.zuul.stats.status.StatusCategory)3 ByteBuf (io.netty.buffer.ByteBuf)3 DefaultHttpContent (io.netty.handler.codec.http.DefaultHttpContent)3 ErrorType (com.netflix.zuul.exception.ErrorType)2 OutboundException (com.netflix.zuul.exception.OutboundException)2 ZuulMessage (com.netflix.zuul.message.ZuulMessage)2 ZuulMessageImpl (com.netflix.zuul.message.ZuulMessageImpl)2 CurrentPassport (com.netflix.zuul.passport.CurrentPassport)2