From bcb62be62bd989c0292e0f8e22a51127907cefdc Mon Sep 17 00:00:00 2001 From: Bennett Lynch Date: Thu, 11 Jun 2020 22:39:10 -0700 Subject: [PATCH] Consolidate HttpObjectDecoder default values into constants (#10344) Motivation HttpObjectDecoder and its associated classes make frequent use of default values for maxInitialLineLength, maxHeaderSize, maxChunkSize, etc. Today, these defaults are defined in-line in constructors and duplicated across many classes. This repetition is more prone to error and inconsistencies. Furthermore, due to the current lack of builder support, if a user wants to change just one of these values (e.g., maxHeaderSize), they are also required to know and repeat the other default values (e.g., maxInitialLineLength and maxChunkSize). The primary motivation for this change is as we are considering adding another constructor parameter (for multiple content length behavior), appending this parameter may require some users to have prior knowledge of the default initialBufferSize, and it would be cleaner to allow them to reference the default constant. Modifications * Consolidate the HttpObjectDecoder default values into public constants * Reference these constants where possible Result No functional change. Additional telescoping constructors will be easier and safer to write. Users may have an easier experience changing single parameters. --- .../netty/handler/codec/http/HttpClientCodec.java | 6 +++++- .../handler/codec/http/HttpObjectDecoder.java | 15 ++++++++++++--- .../handler/codec/http/HttpRequestDecoder.java | 7 ++++--- .../handler/codec/http/HttpResponseDecoder.java | 7 ++++--- .../netty/handler/codec/http/HttpServerCodec.java | 6 +++++- .../io/netty/handler/codec/rtsp/RtspDecoder.java | 10 ---------- .../handler/codec/rtsp/RtspObjectDecoder.java | 4 +++- 7 files changed, 33 insertions(+), 22 deletions(-) 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 1ca4c464ad..2e6652c52a 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 @@ -28,6 +28,10 @@ import java.util.List; import java.util.Queue; import java.util.concurrent.atomic.AtomicLong; +import static io.netty.handler.codec.http.HttpObjectDecoder.DEFAULT_MAX_CHUNK_SIZE; +import static io.netty.handler.codec.http.HttpObjectDecoder.DEFAULT_MAX_HEADER_SIZE; +import static io.netty.handler.codec.http.HttpObjectDecoder.DEFAULT_MAX_INITIAL_LINE_LENGTH; + /** * A combination of {@link HttpRequestEncoder} and {@link HttpResponseDecoder} * which enables easier client side HTTP implementation. {@link HttpClientCodec} @@ -61,7 +65,7 @@ public final class HttpClientCodec extends CombinedChannelDuplexHandler