diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientCodec.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientCodec.java index dd1da34742..8770202d0d 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientCodec.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientCodec.java @@ -61,40 +61,40 @@ public final class HttpClientCodec extends CombinedChannelDuplexHandler 0) { ByteBuf content = buffer.readRetainedSlice(toRead); out.add(new DefaultHttpContent(content)); @@ -286,7 +279,7 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder { return; } case READ_FIXED_LENGTH_CONTENT: { - int readLimit = buffer.readableBytes(); + int toRead = buffer.readableBytes(); // Check if the buffer is readable first as we use the readable byte count // to create the HttpChunk. This is needed as otherwise we may end up with @@ -294,14 +287,14 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder { // handled like it is the last HttpChunk. // // See https://github.com/netty/netty/issues/433 - if (readLimit == 0) { + if (toRead == 0) { return; } - int toRead = Math.min(readLimit, maxChunkSize); if (toRead > chunkSize) { toRead = (int) chunkSize; } + ByteBuf content = buffer.readRetainedSlice(toRead); chunkSize -= toRead; @@ -337,7 +330,7 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder { } case READ_CHUNKED_CONTENT: { assert chunkSize <= Integer.MAX_VALUE; - int toRead = Math.min((int) chunkSize, maxChunkSize); + int toRead = (int) chunkSize; toRead = Math.min(toRead, buffer.readableBytes()); if (toRead == 0) { return; diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestDecoder.java index 24252c7358..1be6cf52e3 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestDecoder.java @@ -66,19 +66,19 @@ public class HttpRequestDecoder extends HttpObjectDecoder { * Creates a new instance with the specified parameters. */ public HttpRequestDecoder( - int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) { - super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true); + int maxInitialLineLength, int maxHeaderSize) { + super(maxInitialLineLength, maxHeaderSize, true); } public HttpRequestDecoder( - int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders) { - super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders); + int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders) { + super(maxInitialLineLength, maxHeaderSize, true, validateHeaders); } public HttpRequestDecoder( - int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, + int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders, int initialBufferSize) { - super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders, initialBufferSize); + super(maxInitialLineLength, maxHeaderSize, true, validateHeaders, initialBufferSize); } @Override diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseDecoder.java index 21491971ef..ede22f4eeb 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseDecoder.java @@ -97,19 +97,19 @@ public class HttpResponseDecoder extends HttpObjectDecoder { * Creates a new instance with the specified parameters. */ public HttpResponseDecoder( - int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) { - super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true); + int maxInitialLineLength, int maxHeaderSize) { + super(maxInitialLineLength, maxHeaderSize, true); } public HttpResponseDecoder( - int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders) { - super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders); + int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders) { + super(maxInitialLineLength, maxHeaderSize, true, validateHeaders); } public HttpResponseDecoder( - int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, + int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders, int initialBufferSize) { - super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders, initialBufferSize); + super(maxInitialLineLength, maxHeaderSize, true, validateHeaders, initialBufferSize); } @Override diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerCodec.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerCodec.java index 4e8d61361b..f72484e4f2 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerCodec.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerCodec.java @@ -41,32 +41,32 @@ public final class HttpServerCodec extends CombinedChannelDuplexHandler() { @Override @@ -174,7 +174,7 @@ public class HttpClientCodecTest { cb.handler(new ChannelInitializer() { @Override protected void initChannel(Channel ch) throws Exception { - ch.pipeline().addLast(new HttpClientCodec(4096, 8192, 8192, true, true)); + ch.pipeline().addLast(new HttpClientCodec(4096, 8192, true, true)); ch.pipeline().addLast(new HttpObjectAggregator(4096)); ch.pipeline().addLast(new SimpleChannelInboundHandler() { @Override @@ -212,7 +212,7 @@ public class HttpClientCodecTest { } private static void testAfterConnect(final boolean parseAfterConnect) throws Exception { - EmbeddedChannel ch = new EmbeddedChannel(new HttpClientCodec(4096, 8192, 8192, true, true, parseAfterConnect)); + EmbeddedChannel ch = new EmbeddedChannel(new HttpClientCodec(4096, 8192, true, true, parseAfterConnect)); Consumer connectResponseConsumer = new Consumer(); sendRequestAndReadResponse(ch, HttpMethod.CONNECT, EMPTY_RESPONSE, connectResponseConsumer); @@ -284,7 +284,7 @@ public class HttpClientCodecTest { "Connection: Upgrade\r\n" + "Upgrade: TLS/1.2, HTTP/1.1\r\n\r\n"; - HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true); + HttpClientCodec codec = new HttpClientCodec(4096, 8192, true); EmbeddedChannel ch = new EmbeddedChannel(codec, new HttpObjectAggregator(1024)); HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecoderTest.java index 7a27a4c08a..b7ea6df628 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecoderTest.java @@ -284,7 +284,7 @@ public class HttpContentDecoderTest { // or removes it completely (handlers down the chain must rely on LastHttpContent object) // force content to be in more than one chunk (5 bytes/chunk) - HttpRequestDecoder decoder = new HttpRequestDecoder(4096, 4096, 5); + HttpRequestDecoder decoder = new HttpRequestDecoder(4096, 4096); HttpContentDecoder decompressor = new HttpContentDecompressor(); EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor); String headers = "POST / HTTP/1.1\r\n" + @@ -313,7 +313,7 @@ public class HttpContentDecoderTest { // case 2: if HttpObjectAggregator is down the chain, then correct Content-Length header must be set // force content to be in more than one chunk (5 bytes/chunk) - HttpRequestDecoder decoder = new HttpRequestDecoder(4096, 4096, 5); + HttpRequestDecoder decoder = new HttpRequestDecoder(4096, 4096); HttpContentDecoder decompressor = new HttpContentDecompressor(); HttpObjectAggregator aggregator = new HttpObjectAggregator(1024); EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor, aggregator); @@ -345,7 +345,7 @@ public class HttpContentDecoderTest { // or removes it completely (handlers down the chain must rely on LastHttpContent object) // force content to be in more than one chunk (5 bytes/chunk) - HttpResponseDecoder decoder = new HttpResponseDecoder(4096, 4096, 5); + HttpResponseDecoder decoder = new HttpResponseDecoder(4096, 4096); HttpContentDecoder decompressor = new HttpContentDecompressor(); EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor); String headers = "HTTP/1.1 200 OK\r\n" + @@ -377,7 +377,7 @@ public class HttpContentDecoderTest { // case 2: if HttpObjectAggregator is down the chain, then correct Content-Length header must be set // force content to be in more than one chunk (5 bytes/chunk) - HttpResponseDecoder decoder = new HttpResponseDecoder(4096, 4096, 5); + HttpResponseDecoder decoder = new HttpResponseDecoder(4096, 4096); HttpContentDecoder decompressor = new HttpContentDecompressor(); HttpObjectAggregator aggregator = new HttpObjectAggregator(1024); EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor, aggregator); @@ -405,7 +405,7 @@ public class HttpContentDecoderTest { @Test public void testFullHttpRequest() { // test that ContentDecoder can be used after the ObjectAggregator - HttpRequestDecoder decoder = new HttpRequestDecoder(4096, 4096, 5); + HttpRequestDecoder decoder = new HttpRequestDecoder(4096, 4096); HttpObjectAggregator aggregator = new HttpObjectAggregator(1024); HttpContentDecoder decompressor = new HttpContentDecompressor(); EmbeddedChannel channel = new EmbeddedChannel(decoder, aggregator, decompressor); @@ -432,7 +432,7 @@ public class HttpContentDecoderTest { @Test public void testFullHttpResponse() { // test that ContentDecoder can be used after the ObjectAggregator - HttpResponseDecoder decoder = new HttpResponseDecoder(4096, 4096, 5); + HttpResponseDecoder decoder = new HttpResponseDecoder(4096, 4096); HttpObjectAggregator aggregator = new HttpObjectAggregator(1024); HttpContentDecoder decompressor = new HttpContentDecompressor(); EmbeddedChannel channel = new EmbeddedChannel(decoder, aggregator, decompressor); @@ -460,7 +460,7 @@ public class HttpContentDecoderTest { @Test public void testFullHttpResponseEOF() { // test that ContentDecoder can be used after the ObjectAggregator - HttpResponseDecoder decoder = new HttpResponseDecoder(4096, 4096, 5); + HttpResponseDecoder decoder = new HttpResponseDecoder(4096, 4096); HttpContentDecoder decompressor = new HttpContentDecompressor(); EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor); String headers = "HTTP/1.1 200 OK\r\n" + 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 45720631c4..7005bfab4d 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 @@ -297,7 +297,7 @@ public class HttpRequestDecoderTest { @Test public void testTooLargeInitialLine() { - EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder(10, 1024, 1024)); + EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder(10, 1024)); String requestStr = "GET /some/path HTTP/1.1\r\n" + "Host: localhost1\r\n\r\n"; @@ -310,7 +310,7 @@ public class HttpRequestDecoderTest { @Test public void testTooLargeHeaders() { - EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder(1024, 10, 1024)); + EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder(1024, 10)); String requestStr = "GET /some/path HTTP/1.1\r\n" + "Host: localhost1\r\n\r\n"; diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseDecoderTest.java index 017dbd5ff9..99707a7e1f 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseDecoderTest.java @@ -49,7 +49,7 @@ public class HttpResponseDecoderTest { public void testMaxHeaderSize1() { final int maxHeaderSize = 8192; - final EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder(4096, maxHeaderSize, 8192)); + final EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder(4096, maxHeaderSize)); final char[] bytes = new char[maxHeaderSize / 2 - 2]; Arrays.fill(bytes, 'a'); @@ -81,7 +81,7 @@ public class HttpResponseDecoderTest { public void testMaxHeaderSize2() { final int maxHeaderSize = 8192; - final EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder(4096, maxHeaderSize, 8192)); + final EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder(4096, maxHeaderSize)); final char[] bytes = new char[maxHeaderSize / 2 - 2]; Arrays.fill(bytes, 'a'); @@ -146,55 +146,6 @@ public class HttpResponseDecoderTest { assertNull(ch.readInbound()); } - @Test - public void testResponseChunkedExceedMaxChunkSize() { - EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder(4096, 8192, 32)); - ch.writeInbound( - Unpooled.copiedBuffer("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n", CharsetUtil.US_ASCII)); - - HttpResponse res = ch.readInbound(); - assertThat(res.protocolVersion(), sameInstance(HttpVersion.HTTP_1_1)); - assertThat(res.status(), is(HttpResponseStatus.OK)); - - byte[] data = new byte[64]; - for (int i = 0; i < data.length; i++) { - data[i] = (byte) i; - } - - for (int i = 0; i < 10; i++) { - assertFalse(ch.writeInbound(Unpooled.copiedBuffer(Integer.toHexString(data.length) + "\r\n", - CharsetUtil.US_ASCII))); - assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(data))); - - byte[] decodedData = new byte[data.length]; - HttpContent content = ch.readInbound(); - assertEquals(32, content.content().readableBytes()); - content.content().readBytes(decodedData, 0, 32); - content.release(); - - content = ch.readInbound(); - assertEquals(32, content.content().readableBytes()); - - content.content().readBytes(decodedData, 32, 32); - - assertArrayEquals(data, decodedData); - content.release(); - - assertFalse(ch.writeInbound(Unpooled.copiedBuffer("\r\n", CharsetUtil.US_ASCII))); - } - - // Write the last chunk. - ch.writeInbound(Unpooled.copiedBuffer("0\r\n\r\n", CharsetUtil.US_ASCII)); - - // Ensure the last chunk was decoded. - LastHttpContent content = ch.readInbound(); - assertFalse(content.content().isReadable()); - content.release(); - - ch.finish(); - assertNull(ch.readInbound()); - } - @Test public void testClosureWithoutContentLength1() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder()); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerCodecTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerCodecTest.java index 17570b758f..8346112ba2 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerCodecTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpServerCodecTest.java @@ -33,7 +33,7 @@ public class HttpServerCodecTest { public void testUnfinishedChunkedHttpRequestIsLastFlag() throws Exception { int maxChunkSize = 2000; - HttpServerCodec httpServerCodec = new HttpServerCodec(1000, 1000, maxChunkSize); + HttpServerCodec httpServerCodec = new HttpServerCodec(1000, 1000); EmbeddedChannel decoderEmbedder = new EmbeddedChannel(httpServerCodec); int totalContentLength = maxChunkSize * 5;