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());
}
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"));
}
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"));
}
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));
}
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));
}
Aggregations