Search in sources :

Example 16 with Headers

use of com.netflix.zuul.message.Headers in project zuul by Netflix.

the class GZipResponseFilter method apply.

@Override
public HttpResponseMessage apply(HttpResponseMessage response) {
    // set Gzip headers
    final Headers respHeaders = response.getHeaders();
    respHeaders.set(HttpHeaderNames.CONTENT_ENCODING, "gzip");
    respHeaders.remove(HttpHeaderNames.CONTENT_LENGTH);
    return response;
}
Also used : Headers(com.netflix.zuul.message.Headers)

Example 17 with Headers

use of com.netflix.zuul.message.Headers in project zuul by Netflix.

the class ProxyEndpoint method transformRequest.

/* static utility methods */
protected HttpRequestMessage transformRequest(HttpRequestMessage requestMsg) {
    final HttpRequestMessage massagedRequest = massageRequestURI(requestMsg);
    Headers headers = massagedRequest.getHeaders();
    REQUEST_HEADERS_TO_REMOVE.forEach(headerName -> headers.remove(headerName.getName()));
    addCustomRequestHeaders(headers);
    // Add X-Forwarded headers if not already there.
    ProxyUtils.addXForwardedHeaders(massagedRequest);
    return massagedRequest;
}
Also used : HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) Headers(com.netflix.zuul.message.Headers)

Example 18 with Headers

use of com.netflix.zuul.message.Headers in project zuul by Netflix.

the class HttpRequestMessageImplTest method getOriginalPort_fallsBackOnUnbracketedIpv6Address.

@Test
public void getOriginalPort_fallsBackOnUnbracketedIpv6Address() throws URISyntaxException {
    Headers headers = new Headers();
    headers.add("Host", "ba::33");
    assertEquals(9999, HttpRequestMessageImpl.getOriginalPort(new SessionContext(), headers, 9999));
}
Also used : Headers(com.netflix.zuul.message.Headers) SessionContext(com.netflix.zuul.context.SessionContext) Test(org.junit.Test)

Example 19 with Headers

use of com.netflix.zuul.message.Headers in project zuul by Netflix.

the class HttpRequestMessageImplTest method testOriginalRequestInfo.

@Test
public void testOriginalRequestInfo() {
    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", new LocalAddress("777"), false);
    request.storeInboundRequest();
    HttpRequestInfo originalRequest = request.getInboundRequest();
    Assert.assertEquals(request.getPort(), originalRequest.getPort());
    Assert.assertEquals(request.getPath(), originalRequest.getPath());
    Assert.assertEquals(request.getQueryParams().getFirst("flag"), originalRequest.getQueryParams().getFirst("flag"));
    Assert.assertEquals(request.getHeaders().getFirst("Host"), originalRequest.getHeaders().getFirst("Host"));
    request.setPort(8080);
    request.setPath("/another/place");
    request.getQueryParams().set("flag", "20");
    request.getHeaders().set("Host", "wah.netflix.com");
    Assert.assertEquals(7002, originalRequest.getPort());
    Assert.assertEquals("/some/where", originalRequest.getPath());
    Assert.assertEquals("5", originalRequest.getQueryParams().getFirst("flag"));
    Assert.assertEquals("blah.netflix.com", originalRequest.getHeaders().getFirst("Host"));
}
Also used : LocalAddress(io.netty.channel.local.LocalAddress) Headers(com.netflix.zuul.message.Headers) SessionContext(com.netflix.zuul.context.SessionContext) Test(org.junit.Test)

Example 20 with Headers

use of com.netflix.zuul.message.Headers in project zuul by Netflix.

the class HttpRequestMessageImplTest method testReconstructURI_immutable.

@Test
public void testReconstructURI_immutable() {
    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", new SocketAddress() {
    }, true);
    // Check it's the same value 2nd time.
    Assert.assertEquals("https://blah.netflix.com:7002/some/where?flag=5", request.reconstructURI());
    Assert.assertEquals("https://blah.netflix.com:7002/some/where?flag=5", request.reconstructURI());
    // Check that cached on 1st usage.
    request = new HttpRequestMessageImpl(new SessionContext(), "HTTP/1.1", "POST", "/some/where", queryParams, headers, "192.168.0.2", "https", 7002, "localhost", new SocketAddress() {
    }, true);
    request = spy(request);
    when(request._reconstructURI()).thenReturn("http://testhost/blah");
    verify(request, times(1))._reconstructURI();
    Assert.assertEquals("http://testhost/blah", request.reconstructURI());
    Assert.assertEquals("http://testhost/blah", request.reconstructURI());
    // Check that throws exception if we try to mutate it.
    try {
        request.setPath("/new-path");
        fail();
    } catch (IllegalStateException e) {
        assertTrue(true);
    }
}
Also used : Headers(com.netflix.zuul.message.Headers) SessionContext(com.netflix.zuul.context.SessionContext) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) 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