diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java index b12ab2d69e..45720631c4 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java @@ -17,6 +17,7 @@ package io.netty.handler.codec.http; import io.netty.buffer.Unpooled; import io.netty.channel.embedded.EmbeddedChannel; +import io.netty.handler.codec.TooLongFrameException; import io.netty.util.AsciiString; import io.netty.util.CharsetUtil; import org.junit.Test; @@ -293,4 +294,30 @@ public class HttpRequestDecoderTest { cnt.release(); assertFalse(channel.finishAndReleaseAll()); } + + @Test + public void testTooLargeInitialLine() { + EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder(10, 1024, 1024)); + String requestStr = "GET /some/path HTTP/1.1\r\n" + + "Host: localhost1\r\n\r\n"; + + assertTrue(channel.writeInbound(Unpooled.copiedBuffer(requestStr, CharsetUtil.US_ASCII))); + HttpRequest request = channel.readInbound(); + assertTrue(request.decoderResult().isFailure()); + assertTrue(request.decoderResult().cause() instanceof TooLongFrameException); + assertFalse(channel.finish()); + } + + @Test + public void testTooLargeHeaders() { + EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder(1024, 10, 1024)); + String requestStr = "GET /some/path HTTP/1.1\r\n" + + "Host: localhost1\r\n\r\n"; + + assertTrue(channel.writeInbound(Unpooled.copiedBuffer(requestStr, CharsetUtil.US_ASCII))); + HttpRequest request = channel.readInbound(); + assertTrue(request.decoderResult().isFailure()); + assertTrue(request.decoderResult().cause() instanceof TooLongFrameException); + assertFalse(channel.finish()); + } }