From d97f17060f56f4ca1c43ac2fe1a2dc8850cee845 Mon Sep 17 00:00:00 2001 From: Luke Daley Date: Mon, 1 Feb 2016 11:24:14 +1000 Subject: [PATCH] Support non chunked HTTP request bodies larger than Integer.MAX_VALUE. Motivation: Request bodies can easily be larger than Integer.MAX_VALUE in practice. There's no reason, or intention, for Netty to impose this artificial constraint. Worse, it currently does not fail if the body is larger than this value; it just silently only reads the first Integer.MAX_VALUE bytes and discards the rest. This restriction doesn't effect chunked transfers, with no Content-Length header. Modifications: Force the use of `long HttpUtil.getContentLength(HttpMessage, long)` instead of `long HttpUtil.getContentLength(HttpMessage, long)`. Result: Netty will support HTTP request bodies of up to Long.MAX_VALUE length. --- .../io/netty/handler/codec/http/HttpObjectAggregator.java | 4 ++-- .../java/io/netty/handler/codec/http/HttpObjectDecoder.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java index 08de185041..635ab81fb1 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java @@ -114,13 +114,13 @@ public class HttpObjectAggregator @Override protected boolean isContentLengthInvalid(HttpMessage start, int maxContentLength) { - return getContentLength(start, -1) > maxContentLength; + return getContentLength(start, -1L) > maxContentLength; } @Override protected Object newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline) { if (HttpUtil.is100ContinueExpected(start)) { - if (getContentLength(start, -1) <= maxContentLength) { + if (getContentLength(start, -1L) <= maxContentLength) { return CONTINUE.duplicate().retain(); } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java index 8136ba7b94..1982e95932 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java @@ -602,7 +602,7 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder { private long contentLength() { if (contentLength == Long.MIN_VALUE) { - contentLength = HttpUtil.getContentLength(message, -1); + contentLength = HttpUtil.getContentLength(message, -1L); } return contentLength; }