Search in sources :

Example 11 with SessionContext

use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.

the class ZuulMessageImplTest method testBufferBody3GetBody.

@Test
public void testBufferBody3GetBody() {
    final ZuulMessage msg = new ZuulMessageImpl(new SessionContext(), new Headers());
    msg.bufferBodyContents(new DefaultHttpContent(Unpooled.copiedBuffer("Hello ".getBytes())));
    msg.bufferBodyContents(new DefaultHttpContent(Unpooled.copiedBuffer("World!".getBytes())));
    msg.bufferBodyContents(new DefaultLastHttpContent());
    final String body = new String(msg.getBody());
    assertTrue(msg.hasBody());
    assertTrue(msg.hasCompleteBody());
    assertEquals("Hello World!", body);
    assertEquals(0, msg.getHeaders().getAll("Content-Length").size());
}
Also used : DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) SessionContext(com.netflix.zuul.context.SessionContext) Test(org.junit.Test)

Example 12 with SessionContext

use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.

the class ZuulMessageImplTest method testSetBodyAsTextGetBody.

@Test
public void testSetBodyAsTextGetBody() {
    final ZuulMessage msg = new ZuulMessageImpl(new SessionContext(), new Headers());
    msg.setBodyAsText(TEXT1);
    final String body = new String(msg.getBody());
    assertTrue(msg.hasBody());
    assertTrue(msg.hasCompleteBody());
    assertEquals(TEXT1, body);
    assertEquals(1, msg.getHeaders().getAll("Content-Length").size());
    assertEquals(String.valueOf(TEXT1.length()), msg.getHeaders().getFirst("Content-Length"));
}
Also used : SessionContext(com.netflix.zuul.context.SessionContext) Test(org.junit.Test)

Example 13 with SessionContext

use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.

the class ZuulMessageImplTest method testMultiSetBodyAsTextGetBody.

@Test
public void testMultiSetBodyAsTextGetBody() {
    final ZuulMessage msg = new ZuulMessageImpl(new SessionContext(), new Headers());
    msg.setBodyAsText(TEXT1);
    String body = new String(msg.getBody());
    assertTrue(msg.hasBody());
    assertTrue(msg.hasCompleteBody());
    assertEquals(TEXT1, body);
    assertEquals(1, msg.getHeaders().getAll("Content-Length").size());
    assertEquals(String.valueOf(TEXT1.length()), msg.getHeaders().getFirst("Content-Length"));
    msg.setBodyAsText(TEXT2);
    body = new String(msg.getBody());
    assertTrue(msg.hasBody());
    assertTrue(msg.hasCompleteBody());
    assertEquals(TEXT2, body);
    assertEquals(1, msg.getHeaders().getAll("Content-Length").size());
    assertEquals(String.valueOf(TEXT2.length()), msg.getHeaders().getFirst("Content-Length"));
}
Also used : SessionContext(com.netflix.zuul.context.SessionContext) Test(org.junit.Test)

Example 14 with SessionContext

use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.

the class HttpRequestMessageImplTest method getOriginalPort_EmptyXFFPort.

@Test
public void getOriginalPort_EmptyXFFPort() throws URISyntaxException {
    Headers headers = new Headers();
    headers.add(HttpHeaderNames.X_FORWARDED_PORT, "");
    // Default to using server port
    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 15 with SessionContext

use of com.netflix.zuul.context.SessionContext 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)

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