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.
This commit is contained in:
Luke Daley 2016-02-01 11:24:14 +10:00 committed by Norman Maurer
parent f990f9983d
commit d97f17060f
2 changed files with 3 additions and 3 deletions

View File

@ -114,13 +114,13 @@ public class HttpObjectAggregator
@Override @Override
protected boolean isContentLengthInvalid(HttpMessage start, int maxContentLength) { protected boolean isContentLengthInvalid(HttpMessage start, int maxContentLength) {
return getContentLength(start, -1) > maxContentLength; return getContentLength(start, -1L) > maxContentLength;
} }
@Override @Override
protected Object newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline) { protected Object newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline) {
if (HttpUtil.is100ContinueExpected(start)) { if (HttpUtil.is100ContinueExpected(start)) {
if (getContentLength(start, -1) <= maxContentLength) { if (getContentLength(start, -1L) <= maxContentLength) {
return CONTINUE.duplicate().retain(); return CONTINUE.duplicate().retain();
} }

View File

@ -602,7 +602,7 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder {
private long contentLength() { private long contentLength() {
if (contentLength == Long.MIN_VALUE) { if (contentLength == Long.MIN_VALUE) {
contentLength = HttpUtil.getContentLength(message, -1); contentLength = HttpUtil.getContentLength(message, -1L);
} }
return contentLength; return contentLength;
} }