Remove the maxChunkSize
parameter for HTTP codecs (#8671)
Motivation: The `maxChunkSize` only serves to split available content into even smaller chunks which is not all that useful since the data is already buffered. Modification: Remove the parameter. Result: Things are simpler. Fixes #8430.
This commit is contained in:
parent
26e1411897
commit
44b919b698
@ -61,40 +61,40 @@ public final class HttpClientCodec extends CombinedChannelDuplexHandler<HttpResp
|
|||||||
* {@code maxChunkSize (8192)}).
|
* {@code maxChunkSize (8192)}).
|
||||||
*/
|
*/
|
||||||
public HttpClientCodec() {
|
public HttpClientCodec() {
|
||||||
this(4096, 8192, 8192, false);
|
this(4096, 8192, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance with the specified decoder options.
|
* Creates a new instance with the specified decoder options.
|
||||||
*/
|
*/
|
||||||
public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) {
|
public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize) {
|
||||||
this(maxInitialLineLength, maxHeaderSize, maxChunkSize, false);
|
this(maxInitialLineLength, maxHeaderSize, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance with the specified decoder options.
|
* Creates a new instance with the specified decoder options.
|
||||||
*/
|
*/
|
||||||
public HttpClientCodec(
|
public HttpClientCodec(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse) {
|
int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse) {
|
||||||
this(maxInitialLineLength, maxHeaderSize, maxChunkSize, failOnMissingResponse, true);
|
this(maxInitialLineLength, maxHeaderSize, failOnMissingResponse, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance with the specified decoder options.
|
* Creates a new instance with the specified decoder options.
|
||||||
*/
|
*/
|
||||||
public HttpClientCodec(
|
public HttpClientCodec(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse,
|
int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse,
|
||||||
boolean validateHeaders) {
|
boolean validateHeaders) {
|
||||||
this(maxInitialLineLength, maxHeaderSize, maxChunkSize, failOnMissingResponse, validateHeaders, false);
|
this(maxInitialLineLength, maxHeaderSize, failOnMissingResponse, validateHeaders, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance with the specified decoder options.
|
* Creates a new instance with the specified decoder options.
|
||||||
*/
|
*/
|
||||||
public HttpClientCodec(
|
public HttpClientCodec(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse,
|
int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse,
|
||||||
boolean validateHeaders, boolean parseHttpAfterConnectRequest) {
|
boolean validateHeaders, boolean parseHttpAfterConnectRequest) {
|
||||||
init(new Decoder(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders), new Encoder());
|
init(new Decoder(maxInitialLineLength, maxHeaderSize, validateHeaders), new Encoder());
|
||||||
this.failOnMissingResponse = failOnMissingResponse;
|
this.failOnMissingResponse = failOnMissingResponse;
|
||||||
this.parseHttpAfterConnectRequest = parseHttpAfterConnectRequest;
|
this.parseHttpAfterConnectRequest = parseHttpAfterConnectRequest;
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ public final class HttpClientCodec extends CombinedChannelDuplexHandler<HttpResp
|
|||||||
public HttpClientCodec(
|
public HttpClientCodec(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse,
|
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse,
|
||||||
boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest) {
|
boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest) {
|
||||||
init(new Decoder(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders, initialBufferSize),
|
init(new Decoder(maxInitialLineLength, maxHeaderSize, validateHeaders, initialBufferSize),
|
||||||
new Encoder());
|
new Encoder());
|
||||||
this.parseHttpAfterConnectRequest = parseHttpAfterConnectRequest;
|
this.parseHttpAfterConnectRequest = parseHttpAfterConnectRequest;
|
||||||
this.failOnMissingResponse = failOnMissingResponse;
|
this.failOnMissingResponse = failOnMissingResponse;
|
||||||
@ -177,13 +177,13 @@ public final class HttpClientCodec extends CombinedChannelDuplexHandler<HttpResp
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class Decoder extends HttpResponseDecoder {
|
private final class Decoder extends HttpResponseDecoder {
|
||||||
Decoder(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders) {
|
Decoder(int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders);
|
super(maxInitialLineLength, maxHeaderSize, validateHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
Decoder(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders,
|
Decoder(int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders,
|
||||||
int initialBufferSize) {
|
int initialBufferSize) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders, initialBufferSize);
|
super(maxInitialLineLength, maxHeaderSize, validateHeaders, initialBufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -102,7 +102,6 @@ import java.util.List;
|
|||||||
public abstract class HttpObjectDecoder extends ByteToMessageDecoder {
|
public abstract class HttpObjectDecoder extends ByteToMessageDecoder {
|
||||||
private static final String EMPTY_VALUE = "";
|
private static final String EMPTY_VALUE = "";
|
||||||
|
|
||||||
private final int maxChunkSize;
|
|
||||||
private final boolean chunkedSupported;
|
private final boolean chunkedSupported;
|
||||||
protected final boolean validateHeaders;
|
protected final boolean validateHeaders;
|
||||||
private final HeaderParser headerParser;
|
private final HeaderParser headerParser;
|
||||||
@ -145,28 +144,28 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder {
|
|||||||
* {@code maxChunkSize (8192)}.
|
* {@code maxChunkSize (8192)}.
|
||||||
*/
|
*/
|
||||||
protected HttpObjectDecoder() {
|
protected HttpObjectDecoder() {
|
||||||
this(4096, 8192, 8192, true);
|
this(4096, 8192, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance with the specified parameters.
|
* Creates a new instance with the specified parameters.
|
||||||
*/
|
*/
|
||||||
protected HttpObjectDecoder(
|
protected HttpObjectDecoder(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean chunkedSupported) {
|
int maxInitialLineLength, int maxHeaderSize, boolean chunkedSupported) {
|
||||||
this(maxInitialLineLength, maxHeaderSize, maxChunkSize, chunkedSupported, true);
|
this(maxInitialLineLength, maxHeaderSize, chunkedSupported, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance with the specified parameters.
|
* Creates a new instance with the specified parameters.
|
||||||
*/
|
*/
|
||||||
protected HttpObjectDecoder(
|
protected HttpObjectDecoder(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize,
|
int maxInitialLineLength, int maxHeaderSize,
|
||||||
boolean chunkedSupported, boolean validateHeaders) {
|
boolean chunkedSupported, boolean validateHeaders) {
|
||||||
this(maxInitialLineLength, maxHeaderSize, maxChunkSize, chunkedSupported, validateHeaders, 128);
|
this(maxInitialLineLength, maxHeaderSize, chunkedSupported, validateHeaders, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpObjectDecoder(
|
protected HttpObjectDecoder(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize,
|
int maxInitialLineLength, int maxHeaderSize,
|
||||||
boolean chunkedSupported, boolean validateHeaders, int initialBufferSize) {
|
boolean chunkedSupported, boolean validateHeaders, int initialBufferSize) {
|
||||||
if (maxInitialLineLength <= 0) {
|
if (maxInitialLineLength <= 0) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
@ -178,15 +177,9 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder {
|
|||||||
"maxHeaderSize must be a positive integer: " +
|
"maxHeaderSize must be a positive integer: " +
|
||||||
maxHeaderSize);
|
maxHeaderSize);
|
||||||
}
|
}
|
||||||
if (maxChunkSize <= 0) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"maxChunkSize must be a positive integer: " +
|
|
||||||
maxChunkSize);
|
|
||||||
}
|
|
||||||
AppendableCharSequence seq = new AppendableCharSequence(initialBufferSize);
|
AppendableCharSequence seq = new AppendableCharSequence(initialBufferSize);
|
||||||
lineParser = new LineParser(seq, maxInitialLineLength);
|
lineParser = new LineParser(seq, maxInitialLineLength);
|
||||||
headerParser = new HeaderParser(seq, maxHeaderSize);
|
headerParser = new HeaderParser(seq, maxHeaderSize);
|
||||||
this.maxChunkSize = maxChunkSize;
|
|
||||||
this.chunkedSupported = chunkedSupported;
|
this.chunkedSupported = chunkedSupported;
|
||||||
this.validateHeaders = validateHeaders;
|
this.validateHeaders = validateHeaders;
|
||||||
}
|
}
|
||||||
@ -278,7 +271,7 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder {
|
|||||||
}
|
}
|
||||||
case READ_VARIABLE_LENGTH_CONTENT: {
|
case READ_VARIABLE_LENGTH_CONTENT: {
|
||||||
// Keep reading data as a chunk until the end of connection is reached.
|
// Keep reading data as a chunk until the end of connection is reached.
|
||||||
int toRead = Math.min(buffer.readableBytes(), maxChunkSize);
|
int toRead = buffer.readableBytes();
|
||||||
if (toRead > 0) {
|
if (toRead > 0) {
|
||||||
ByteBuf content = buffer.readRetainedSlice(toRead);
|
ByteBuf content = buffer.readRetainedSlice(toRead);
|
||||||
out.add(new DefaultHttpContent(content));
|
out.add(new DefaultHttpContent(content));
|
||||||
@ -286,7 +279,7 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case READ_FIXED_LENGTH_CONTENT: {
|
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
|
// 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
|
// 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.
|
// handled like it is the last HttpChunk.
|
||||||
//
|
//
|
||||||
// See https://github.com/netty/netty/issues/433
|
// See https://github.com/netty/netty/issues/433
|
||||||
if (readLimit == 0) {
|
if (toRead == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int toRead = Math.min(readLimit, maxChunkSize);
|
|
||||||
if (toRead > chunkSize) {
|
if (toRead > chunkSize) {
|
||||||
toRead = (int) chunkSize;
|
toRead = (int) chunkSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuf content = buffer.readRetainedSlice(toRead);
|
ByteBuf content = buffer.readRetainedSlice(toRead);
|
||||||
chunkSize -= toRead;
|
chunkSize -= toRead;
|
||||||
|
|
||||||
@ -337,7 +330,7 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder {
|
|||||||
}
|
}
|
||||||
case READ_CHUNKED_CONTENT: {
|
case READ_CHUNKED_CONTENT: {
|
||||||
assert chunkSize <= Integer.MAX_VALUE;
|
assert chunkSize <= Integer.MAX_VALUE;
|
||||||
int toRead = Math.min((int) chunkSize, maxChunkSize);
|
int toRead = (int) chunkSize;
|
||||||
toRead = Math.min(toRead, buffer.readableBytes());
|
toRead = Math.min(toRead, buffer.readableBytes());
|
||||||
if (toRead == 0) {
|
if (toRead == 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -66,19 +66,19 @@ public class HttpRequestDecoder extends HttpObjectDecoder {
|
|||||||
* Creates a new instance with the specified parameters.
|
* Creates a new instance with the specified parameters.
|
||||||
*/
|
*/
|
||||||
public HttpRequestDecoder(
|
public HttpRequestDecoder(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) {
|
int maxInitialLineLength, int maxHeaderSize) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true);
|
super(maxInitialLineLength, maxHeaderSize, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpRequestDecoder(
|
public HttpRequestDecoder(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders) {
|
int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders);
|
super(maxInitialLineLength, maxHeaderSize, true, validateHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpRequestDecoder(
|
public HttpRequestDecoder(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders,
|
int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders,
|
||||||
int initialBufferSize) {
|
int initialBufferSize) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders, initialBufferSize);
|
super(maxInitialLineLength, maxHeaderSize, true, validateHeaders, initialBufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -97,19 +97,19 @@ public class HttpResponseDecoder extends HttpObjectDecoder {
|
|||||||
* Creates a new instance with the specified parameters.
|
* Creates a new instance with the specified parameters.
|
||||||
*/
|
*/
|
||||||
public HttpResponseDecoder(
|
public HttpResponseDecoder(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) {
|
int maxInitialLineLength, int maxHeaderSize) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true);
|
super(maxInitialLineLength, maxHeaderSize, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponseDecoder(
|
public HttpResponseDecoder(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders) {
|
int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders);
|
super(maxInitialLineLength, maxHeaderSize, true, validateHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponseDecoder(
|
public HttpResponseDecoder(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders,
|
int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders,
|
||||||
int initialBufferSize) {
|
int initialBufferSize) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders, initialBufferSize);
|
super(maxInitialLineLength, maxHeaderSize, true, validateHeaders, initialBufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,32 +41,32 @@ public final class HttpServerCodec extends CombinedChannelDuplexHandler<HttpRequ
|
|||||||
* {@code maxChunkSize (8192)}).
|
* {@code maxChunkSize (8192)}).
|
||||||
*/
|
*/
|
||||||
public HttpServerCodec() {
|
public HttpServerCodec() {
|
||||||
this(4096, 8192, 8192);
|
this(4096, 8192);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance with the specified decoder options.
|
* Creates a new instance with the specified decoder options.
|
||||||
*/
|
*/
|
||||||
public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) {
|
public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize) {
|
||||||
init(new HttpServerRequestDecoder(maxInitialLineLength, maxHeaderSize, maxChunkSize),
|
init(new HttpServerRequestDecoder(maxInitialLineLength, maxHeaderSize),
|
||||||
new HttpServerResponseEncoder());
|
new HttpServerResponseEncoder());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance with the specified decoder options.
|
* Creates a new instance with the specified decoder options.
|
||||||
*/
|
*/
|
||||||
public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders) {
|
public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders) {
|
||||||
init(new HttpServerRequestDecoder(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders),
|
init(new HttpServerRequestDecoder(maxInitialLineLength, maxHeaderSize, validateHeaders),
|
||||||
new HttpServerResponseEncoder());
|
new HttpServerResponseEncoder());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance with the specified decoder options.
|
* Creates a new instance with the specified decoder options.
|
||||||
*/
|
*/
|
||||||
public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders,
|
public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders,
|
||||||
int initialBufferSize) {
|
int initialBufferSize) {
|
||||||
init(
|
init(
|
||||||
new HttpServerRequestDecoder(maxInitialLineLength, maxHeaderSize, maxChunkSize,
|
new HttpServerRequestDecoder(maxInitialLineLength, maxHeaderSize,
|
||||||
validateHeaders, initialBufferSize),
|
validateHeaders, initialBufferSize),
|
||||||
new HttpServerResponseEncoder());
|
new HttpServerResponseEncoder());
|
||||||
}
|
}
|
||||||
@ -81,18 +81,18 @@ public final class HttpServerCodec extends CombinedChannelDuplexHandler<HttpRequ
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class HttpServerRequestDecoder extends HttpRequestDecoder {
|
private final class HttpServerRequestDecoder extends HttpRequestDecoder {
|
||||||
public HttpServerRequestDecoder(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) {
|
public HttpServerRequestDecoder(int maxInitialLineLength, int maxHeaderSize) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxChunkSize);
|
super(maxInitialLineLength, maxHeaderSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpServerRequestDecoder(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize,
|
public HttpServerRequestDecoder(int maxInitialLineLength, int maxHeaderSize,
|
||||||
boolean validateHeaders) {
|
boolean validateHeaders) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders);
|
super(maxInitialLineLength, maxHeaderSize, validateHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpServerRequestDecoder(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize,
|
public HttpServerRequestDecoder(int maxInitialLineLength, int maxHeaderSize,
|
||||||
boolean validateHeaders, int initialBufferSize) {
|
boolean validateHeaders, int initialBufferSize) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders, initialBufferSize);
|
super(maxInitialLineLength, maxHeaderSize, validateHeaders, initialBufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -106,7 +106,7 @@ public class RtspDecoder extends HttpObjectDecoder {
|
|||||||
public RtspDecoder(final int maxInitialLineLength,
|
public RtspDecoder(final int maxInitialLineLength,
|
||||||
final int maxHeaderSize,
|
final int maxHeaderSize,
|
||||||
final int maxContentLength) {
|
final int maxContentLength) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxContentLength * 2, false);
|
super(maxInitialLineLength, maxHeaderSize, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,7 +122,6 @@ public class RtspDecoder extends HttpObjectDecoder {
|
|||||||
final boolean validateHeaders) {
|
final boolean validateHeaders) {
|
||||||
super(maxInitialLineLength,
|
super(maxInitialLineLength,
|
||||||
maxHeaderSize,
|
maxHeaderSize,
|
||||||
maxContentLength * 2,
|
|
||||||
false,
|
false,
|
||||||
validateHeaders);
|
validateHeaders);
|
||||||
}
|
}
|
||||||
|
@ -55,23 +55,22 @@ public abstract class RtspObjectDecoder extends HttpObjectDecoder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance with the default
|
* Creates a new instance with the default
|
||||||
* {@code maxInitialLineLength (4096)}, {@code maxHeaderSize (8192)}, and
|
* {@code maxInitialLineLength (4096)}, {@code maxHeaderSize (8192)}.
|
||||||
* {@code maxContentLength (8192)}.
|
|
||||||
*/
|
*/
|
||||||
protected RtspObjectDecoder() {
|
protected RtspObjectDecoder() {
|
||||||
this(4096, 8192, 8192);
|
this(4096, 8192);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance with the specified parameters.
|
* Creates a new instance with the specified parameters.
|
||||||
*/
|
*/
|
||||||
protected RtspObjectDecoder(int maxInitialLineLength, int maxHeaderSize, int maxContentLength) {
|
protected RtspObjectDecoder(int maxInitialLineLength, int maxHeaderSize) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxContentLength * 2, false);
|
super(maxInitialLineLength, maxHeaderSize, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RtspObjectDecoder(
|
protected RtspObjectDecoder(
|
||||||
int maxInitialLineLength, int maxHeaderSize, int maxContentLength, boolean validateHeaders) {
|
int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders) {
|
||||||
super(maxInitialLineLength, maxHeaderSize, maxContentLength * 2, false, validateHeaders);
|
super(maxInitialLineLength, maxHeaderSize, false, validateHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,7 +59,7 @@ public class HttpClientCodecTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectWithResponseContent() {
|
public void testConnectWithResponseContent() {
|
||||||
HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true);
|
HttpClientCodec codec = new HttpClientCodec(4096, 8192, true);
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(codec);
|
EmbeddedChannel ch = new EmbeddedChannel(codec);
|
||||||
|
|
||||||
sendRequestAndReadResponse(ch, HttpMethod.CONNECT, RESPONSE);
|
sendRequestAndReadResponse(ch, HttpMethod.CONNECT, RESPONSE);
|
||||||
@ -68,7 +68,7 @@ public class HttpClientCodecTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailsNotOnRequestResponseChunked() {
|
public void testFailsNotOnRequestResponseChunked() {
|
||||||
HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true);
|
HttpClientCodec codec = new HttpClientCodec(4096, 8192, true);
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(codec);
|
EmbeddedChannel ch = new EmbeddedChannel(codec);
|
||||||
|
|
||||||
sendRequestAndReadResponse(ch, HttpMethod.GET, CHUNKED_RESPONSE);
|
sendRequestAndReadResponse(ch, HttpMethod.GET, CHUNKED_RESPONSE);
|
||||||
@ -77,7 +77,7 @@ public class HttpClientCodecTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailsOnMissingResponse() {
|
public void testFailsOnMissingResponse() {
|
||||||
HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true);
|
HttpClientCodec codec = new HttpClientCodec(4096, 8192, true);
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(codec);
|
EmbeddedChannel ch = new EmbeddedChannel(codec);
|
||||||
|
|
||||||
assertTrue(ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
|
assertTrue(ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
|
||||||
@ -95,7 +95,7 @@ public class HttpClientCodecTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailsOnIncompleteChunkedResponse() {
|
public void testFailsOnIncompleteChunkedResponse() {
|
||||||
HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true);
|
HttpClientCodec codec = new HttpClientCodec(4096, 8192, true);
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(codec);
|
EmbeddedChannel ch = new EmbeddedChannel(codec);
|
||||||
|
|
||||||
ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
|
ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
|
||||||
@ -130,7 +130,7 @@ public class HttpClientCodecTest {
|
|||||||
@Override
|
@Override
|
||||||
protected void initChannel(Channel ch) throws Exception {
|
protected void initChannel(Channel ch) throws Exception {
|
||||||
// Don't use the HttpServerCodec, because we don't want to have content-length or anything added.
|
// Don't use the HttpServerCodec, because we don't want to have content-length or anything added.
|
||||||
ch.pipeline().addLast(new HttpRequestDecoder(4096, 8192, 8192, true));
|
ch.pipeline().addLast(new HttpRequestDecoder(4096, 8192, true));
|
||||||
ch.pipeline().addLast(new HttpObjectAggregator(4096));
|
ch.pipeline().addLast(new HttpObjectAggregator(4096));
|
||||||
ch.pipeline().addLast(new SimpleChannelInboundHandler<FullHttpRequest>() {
|
ch.pipeline().addLast(new SimpleChannelInboundHandler<FullHttpRequest>() {
|
||||||
@Override
|
@Override
|
||||||
@ -174,7 +174,7 @@ public class HttpClientCodecTest {
|
|||||||
cb.handler(new ChannelInitializer<Channel>() {
|
cb.handler(new ChannelInitializer<Channel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(Channel ch) throws Exception {
|
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 HttpObjectAggregator(4096));
|
||||||
ch.pipeline().addLast(new SimpleChannelInboundHandler<FullHttpResponse>() {
|
ch.pipeline().addLast(new SimpleChannelInboundHandler<FullHttpResponse>() {
|
||||||
@Override
|
@Override
|
||||||
@ -212,7 +212,7 @@ public class HttpClientCodecTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void testAfterConnect(final boolean parseAfterConnect) throws Exception {
|
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();
|
Consumer connectResponseConsumer = new Consumer();
|
||||||
sendRequestAndReadResponse(ch, HttpMethod.CONNECT, EMPTY_RESPONSE, connectResponseConsumer);
|
sendRequestAndReadResponse(ch, HttpMethod.CONNECT, EMPTY_RESPONSE, connectResponseConsumer);
|
||||||
@ -284,7 +284,7 @@ public class HttpClientCodecTest {
|
|||||||
"Connection: Upgrade\r\n" +
|
"Connection: Upgrade\r\n" +
|
||||||
"Upgrade: TLS/1.2, HTTP/1.1\r\n\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));
|
EmbeddedChannel ch = new EmbeddedChannel(codec, new HttpObjectAggregator(1024));
|
||||||
|
|
||||||
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/");
|
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/");
|
||||||
|
@ -284,7 +284,7 @@ public class HttpContentDecoderTest {
|
|||||||
// or removes it completely (handlers down the chain must rely on LastHttpContent object)
|
// 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)
|
// 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();
|
HttpContentDecoder decompressor = new HttpContentDecompressor();
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor);
|
EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor);
|
||||||
String headers = "POST / HTTP/1.1\r\n" +
|
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
|
// 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)
|
// 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();
|
HttpContentDecoder decompressor = new HttpContentDecompressor();
|
||||||
HttpObjectAggregator aggregator = new HttpObjectAggregator(1024);
|
HttpObjectAggregator aggregator = new HttpObjectAggregator(1024);
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor, aggregator);
|
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)
|
// 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)
|
// 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();
|
HttpContentDecoder decompressor = new HttpContentDecompressor();
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor);
|
EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor);
|
||||||
String headers = "HTTP/1.1 200 OK\r\n" +
|
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
|
// 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)
|
// 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();
|
HttpContentDecoder decompressor = new HttpContentDecompressor();
|
||||||
HttpObjectAggregator aggregator = new HttpObjectAggregator(1024);
|
HttpObjectAggregator aggregator = new HttpObjectAggregator(1024);
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor, aggregator);
|
EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor, aggregator);
|
||||||
@ -405,7 +405,7 @@ public class HttpContentDecoderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testFullHttpRequest() {
|
public void testFullHttpRequest() {
|
||||||
// test that ContentDecoder can be used after the ObjectAggregator
|
// 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);
|
HttpObjectAggregator aggregator = new HttpObjectAggregator(1024);
|
||||||
HttpContentDecoder decompressor = new HttpContentDecompressor();
|
HttpContentDecoder decompressor = new HttpContentDecompressor();
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(decoder, aggregator, decompressor);
|
EmbeddedChannel channel = new EmbeddedChannel(decoder, aggregator, decompressor);
|
||||||
@ -432,7 +432,7 @@ public class HttpContentDecoderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testFullHttpResponse() {
|
public void testFullHttpResponse() {
|
||||||
// test that ContentDecoder can be used after the ObjectAggregator
|
// 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);
|
HttpObjectAggregator aggregator = new HttpObjectAggregator(1024);
|
||||||
HttpContentDecoder decompressor = new HttpContentDecompressor();
|
HttpContentDecoder decompressor = new HttpContentDecompressor();
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(decoder, aggregator, decompressor);
|
EmbeddedChannel channel = new EmbeddedChannel(decoder, aggregator, decompressor);
|
||||||
@ -460,7 +460,7 @@ public class HttpContentDecoderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testFullHttpResponseEOF() {
|
public void testFullHttpResponseEOF() {
|
||||||
// test that ContentDecoder can be used after the ObjectAggregator
|
// 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();
|
HttpContentDecoder decompressor = new HttpContentDecompressor();
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor);
|
EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor);
|
||||||
String headers = "HTTP/1.1 200 OK\r\n" +
|
String headers = "HTTP/1.1 200 OK\r\n" +
|
||||||
|
@ -297,7 +297,7 @@ public class HttpRequestDecoderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTooLargeInitialLine() {
|
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" +
|
String requestStr = "GET /some/path HTTP/1.1\r\n" +
|
||||||
"Host: localhost1\r\n\r\n";
|
"Host: localhost1\r\n\r\n";
|
||||||
|
|
||||||
@ -310,7 +310,7 @@ public class HttpRequestDecoderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTooLargeHeaders() {
|
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" +
|
String requestStr = "GET /some/path HTTP/1.1\r\n" +
|
||||||
"Host: localhost1\r\n\r\n";
|
"Host: localhost1\r\n\r\n";
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public class HttpResponseDecoderTest {
|
|||||||
public void testMaxHeaderSize1() {
|
public void testMaxHeaderSize1() {
|
||||||
final int maxHeaderSize = 8192;
|
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];
|
final char[] bytes = new char[maxHeaderSize / 2 - 2];
|
||||||
Arrays.fill(bytes, 'a');
|
Arrays.fill(bytes, 'a');
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ public class HttpResponseDecoderTest {
|
|||||||
public void testMaxHeaderSize2() {
|
public void testMaxHeaderSize2() {
|
||||||
final int maxHeaderSize = 8192;
|
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];
|
final char[] bytes = new char[maxHeaderSize / 2 - 2];
|
||||||
Arrays.fill(bytes, 'a');
|
Arrays.fill(bytes, 'a');
|
||||||
|
|
||||||
@ -146,55 +146,6 @@ public class HttpResponseDecoderTest {
|
|||||||
assertNull(ch.readInbound());
|
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
|
@Test
|
||||||
public void testClosureWithoutContentLength1() throws Exception {
|
public void testClosureWithoutContentLength1() throws Exception {
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
|
EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
|
||||||
|
@ -33,7 +33,7 @@ public class HttpServerCodecTest {
|
|||||||
public void testUnfinishedChunkedHttpRequestIsLastFlag() throws Exception {
|
public void testUnfinishedChunkedHttpRequestIsLastFlag() throws Exception {
|
||||||
|
|
||||||
int maxChunkSize = 2000;
|
int maxChunkSize = 2000;
|
||||||
HttpServerCodec httpServerCodec = new HttpServerCodec(1000, 1000, maxChunkSize);
|
HttpServerCodec httpServerCodec = new HttpServerCodec(1000, 1000);
|
||||||
EmbeddedChannel decoderEmbedder = new EmbeddedChannel(httpServerCodec);
|
EmbeddedChannel decoderEmbedder = new EmbeddedChannel(httpServerCodec);
|
||||||
|
|
||||||
int totalContentLength = maxChunkSize * 5;
|
int totalContentLength = maxChunkSize * 5;
|
||||||
|
Loading…
Reference in New Issue
Block a user