Search in sources :

Example 1 with PassportLoggingHandler

use of com.netflix.zuul.netty.insights.PassportLoggingHandler 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());
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpRequestEncoder(io.netty.handler.codec.http.HttpRequestEncoder) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) SessionContext(com.netflix.zuul.context.SessionContext) ByteBuf(io.netty.buffer.ByteBuf) PassportLoggingHandler(com.netflix.zuul.netty.insights.PassportLoggingHandler) Test(org.junit.Test)

Example 2 with PassportLoggingHandler

use of com.netflix.zuul.netty.insights.PassportLoggingHandler in project zuul by Netflix.

the class ClientRequestReceiverTest method maxHeaderSizeExceeded_setBadRequestStatus.

@Test
public void maxHeaderSizeExceeded_setBadRequestStatus() {
    int maxInitialLineLength = BaseZuulChannelInitializer.MAX_INITIAL_LINE_LENGTH.get();
    int maxHeaderSize = 10;
    int maxChunkSize = BaseZuulChannelInitializer.MAX_CHUNK_SIZE.get();
    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(maxInitialLineLength, maxHeaderSize, maxChunkSize, false));
    channel.pipeline().addLast(receiver);
    channel.pipeline().addLast(loggingHandler);
    String str = "test-header-value";
    ByteBuf buf = Unpooled.buffer(1);
    HttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/post", buf);
    for (int i = 0; i < 100; i++) {
        httpRequest.headers().add("test-header" + i, str);
    }
    channel.writeOutbound(httpRequest);
    ByteBuf byteBuf = channel.readOutbound();
    channel.writeInbound(byteBuf);
    channel.readInbound();
    channel.close();
    HttpRequestMessage request = ClientRequestReceiver.getRequestFromChannel(channel);
    assertEquals(StatusCategoryUtils.getStatusCategory(request.getContext()), ZuulStatusCategory.FAILURE_CLIENT_BAD_REQUEST);
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpRequestEncoder(io.netty.handler.codec.http.HttpRequestEncoder) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ByteBuf(io.netty.buffer.ByteBuf) PassportLoggingHandler(com.netflix.zuul.netty.insights.PassportLoggingHandler) Test(org.junit.Test)

Aggregations

DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)2 HttpRequestMessage (com.netflix.zuul.message.http.HttpRequestMessage)2 PassportLoggingHandler (com.netflix.zuul.netty.insights.PassportLoggingHandler)2 ByteBuf (io.netty.buffer.ByteBuf)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)2 HttpRequest (io.netty.handler.codec.http.HttpRequest)2 HttpRequestEncoder (io.netty.handler.codec.http.HttpRequestEncoder)2 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)2 Test (org.junit.Test)2 SessionContext (com.netflix.zuul.context.SessionContext)1