use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class ZuulMessageImplTest method testMultiSetBodyGetBody.
@Test
public void testMultiSetBodyGetBody() {
final ZuulMessage msg = new ZuulMessageImpl(new SessionContext(), new Headers());
msg.setBody(TEXT1.getBytes());
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.setBody(TEXT2.getBytes());
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 ZuulMessageImplTest method testBufferBody3GetBodyAsText.
@Test
public void testBufferBody3GetBodyAsText() {
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 = msg.getBodyAsText();
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 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));
}
use of com.netflix.zuul.context.SessionContext 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"));
}
use of com.netflix.zuul.context.SessionContext 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);
}
}
Aggregations