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 e7a7610a9d..84f7b5c8e6 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 @@ -94,6 +94,17 @@ public final class HttpClientCodec this.failOnMissingResponse = failOnMissingResponse; } + /** + * Creates a new instance with the specified decoder options. + */ + public HttpClientCodec( + int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, + boolean validateHeaders, int initialBufferSize) { + init(new Decoder(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders, initialBufferSize), + new Encoder()); + this.failOnMissingResponse = failOnMissingResponse; + } + private final class Encoder extends HttpRequestEncoder { @Override @@ -120,6 +131,11 @@ public final class HttpClientCodec super(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders); } + Decoder(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, + int initialBufferSize) { + super(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders, initialBufferSize); + } + @Override protected void decode( ChannelHandlerContext ctx, ByteBuf buffer, List out) throws Exception { 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 063f220edd..d2a662bbd7 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 @@ -162,7 +162,12 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder { protected HttpObjectDecoder( int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean chunkedSupported, boolean validateHeaders) { + this(maxInitialLineLength, maxHeaderSize, maxChunkSize, chunkedSupported, validateHeaders, 128); + } + protected HttpObjectDecoder( + int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, + boolean chunkedSupported, boolean validateHeaders, int initialBufferSize) { if (maxInitialLineLength <= 0) { throw new IllegalArgumentException( "maxInitialLineLength must be a positive integer: " + @@ -178,12 +183,12 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder { "maxChunkSize must be a positive integer: " + maxChunkSize); } + AppendableCharSequence seq = new AppendableCharSequence(initialBufferSize); + lineParser = new LineParser(seq, maxInitialLineLength); + headerParser = new HeaderParser(seq, maxHeaderSize); this.maxChunkSize = maxChunkSize; this.chunkedSupported = chunkedSupported; this.validateHeaders = validateHeaders; - AppendableCharSequence seq = new AppendableCharSequence(128); - lineParser = new LineParser(seq, maxInitialLineLength); - headerParser = new HeaderParser(seq, maxHeaderSize); } @Override 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 91364a9cf3..0fd2d02914 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 @@ -76,6 +76,12 @@ public class HttpRequestDecoder extends HttpObjectDecoder { super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders); } + public HttpRequestDecoder( + int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, + int initialBufferSize) { + super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders, initialBufferSize); + } + @Override protected HttpMessage createMessage(String[] initialLine) throws Exception { return new DefaultHttpRequest( 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 485d0a26e3..17043ff3e7 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 @@ -107,6 +107,12 @@ public class HttpResponseDecoder extends HttpObjectDecoder { super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders); } + public HttpResponseDecoder( + int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, + int initialBufferSize) { + super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders, initialBufferSize); + } + @Override protected HttpMessage createMessage(String[] initialLine) { return new DefaultHttpResponse( 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 c10185a51b..98e95bfee7 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 @@ -50,4 +50,14 @@ public final class HttpServerCodec super(new HttpRequestDecoder(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders), new HttpResponseEncoder()); } + + /** + * Creates a new instance with the specified decoder options. + */ + public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, + int initialBufferSize) { + super( + new HttpRequestDecoder(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders, initialBufferSize), + new HttpResponseEncoder()); + } }