use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class ZuulFilterChainRunnerTest method before.
@Before
public void before() {
SessionContext context = new SessionContext();
Headers headers = new Headers();
ChannelHandlerContext chc = mock(ChannelHandlerContext.class);
when(chc.executor()).thenReturn(ImmediateEventExecutor.INSTANCE);
context.put(NETTY_SERVER_CHANNEL_HANDLER_CONTEXT, chc);
request = new HttpRequestMessageImpl(context, "http", "GET", "/foo/bar", new HttpQueryParams(), headers, "127.0.0.1", "http", 8080, "server123");
request.storeInboundRequest();
response = new HttpResponseMessageImpl(context, request, 200);
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class HttpUtilsTest method getBodySizeIfKnown_returnsResponseBodySize.
@Test
public void getBodySizeIfKnown_returnsResponseBodySize() {
SessionContext context = new SessionContext();
Headers headers = new Headers();
HttpQueryParams queryParams = new HttpQueryParams();
HttpRequestMessage request = new HttpRequestMessageImpl(context, "http", "GET", "/path", queryParams, headers, "127.0.0.1", "scheme", 6666, "server-name");
request.storeInboundRequest();
HttpResponseMessage response = new HttpResponseMessageImpl(context, request, 200);
response.setBodyAsText("Hello world");
assertThat(HttpUtils.getBodySizeIfKnown(response)).isEqualTo(Integer.valueOf(11));
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class ClientRequestReceiverTest method multipleHostHeaders_setBadRequestStatus.
@Test
public void multipleHostHeaders_setBadRequestStatus() {
ClientRequestReceiver receiver = new ClientRequestReceiver(null);
EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestEncoder());
PassportLoggingHandler loggingHandler = new PassportLoggingHandler(new DefaultRegistry());
// Required for messages
channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234);
channel.pipeline().addLast(new HttpServerCodec());
channel.pipeline().addLast(receiver);
channel.pipeline().addLast(loggingHandler);
HttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/post");
httpRequest.headers().add("Host", "foo.bar.com");
httpRequest.headers().add("Host", "bar.foo.com");
channel.writeOutbound(httpRequest);
ByteBuf byteBuf = channel.readOutbound();
channel.writeInbound(byteBuf);
channel.readInbound();
channel.close();
HttpRequestMessage request = ClientRequestReceiver.getRequestFromChannel(channel);
SessionContext context = request.getContext();
assertEquals(StatusCategoryUtils.getStatusCategory(context), ZuulStatusCategory.FAILURE_CLIENT_BAD_REQUEST);
assertEquals("Multiple Host headers", context.getError().getMessage());
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class ZuulMessageImplTest method testClone.
@Test
public void testClone() {
SessionContext ctx1 = new SessionContext();
ctx1.set("k1", "v1");
Headers headers1 = new Headers();
headers1.set("k1", "v1");
ZuulMessage msg1 = new ZuulMessageImpl(ctx1, headers1);
ZuulMessage msg2 = msg1.clone();
assertEquals(msg1.getBodyAsText(), msg2.getBodyAsText());
assertEquals(msg1.getHeaders(), msg2.getHeaders());
assertEquals(msg1.getContext(), msg2.getContext());
// Verify that values of the 2 messages are decoupled.
msg1.getHeaders().set("k1", "v_new");
msg1.getContext().set("k1", "v_new");
assertEquals("v1", msg2.getHeaders().getFirst("k1"));
assertEquals("v1", msg2.getContext().get("k1"));
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class ZuulMessageImplTest method testSetBodyAsTextGetBodyAsText.
@Test
public void testSetBodyAsTextGetBodyAsText() {
final ZuulMessage msg = new ZuulMessageImpl(new SessionContext(), new Headers());
msg.setBodyAsText(TEXT1);
final String body = msg.getBodyAsText();
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"));
}
Aggregations