Class HttpDecoderConfig
- java.lang.Object
-
- io.netty.handler.codec.http.HttpDecoderConfig
-
- All Implemented Interfaces:
java.lang.Cloneable
public final class HttpDecoderConfig extends java.lang.Object implements java.lang.CloneableA configuration object for specifying the behaviour ofHttpObjectDecoderand its subclasses.The
HttpDecoderConfigobjects are mutable to reduce allocation, but alsoCloneablein case a defensive copy is needed.
-
-
Constructor Summary
Constructors Constructor Description HttpDecoderConfig()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpDecoderConfigclone()HttpHeadersFactorygetHeadersFactory()intgetInitialBufferSize()intgetMaxChunkSize()intgetMaxHeaderSize()intgetMaxInitialLineLength()HttpHeadersFactorygetTrailersFactory()booleanisAllowDuplicateContentLengths()booleanisAllowPartialChunks()booleanisChunkedSupported()booleanisStrictLineParsing()HttpDecoderConfigsetAllowDuplicateContentLengths(boolean allowDuplicateContentLengths)Set whether more than oneContent-Lengthheader is allowed.HttpDecoderConfigsetAllowPartialChunks(boolean allowPartialChunks)Set whether chunks can be split into multiple messages, if their chunk size exceeds the size of the input buffer.HttpDecoderConfigsetChunkedSupported(boolean chunkedSupported)Set whetherTransfer-Encoding: Chunkedshould be supported.HttpDecoderConfigsetHeadersFactory(HttpHeadersFactory headersFactory)Set theHttpHeadersFactoryto use when creating new HTTP headers objects.HttpDecoderConfigsetInitialBufferSize(int initialBufferSize)Set the initial size of the temporary buffer used when parsing the lines of the HTTP headers.HttpDecoderConfigsetMaxChunkSize(int maxChunkSize)Set the maximum chunk size.HttpDecoderConfigsetMaxHeaderSize(int maxHeaderSize)Set the maximum line length of header lines.HttpDecoderConfigsetMaxInitialLineLength(int maxInitialLineLength)Set the maximum length of the first line of the HTTP header.HttpDecoderConfigsetStrictLineParsing(boolean strictLineParsing)The RFC 9112 specification for the HTTP protocol says that the initial start-line, and the following header field-lines, must be separated by a Carriage Return (CR) and Line Feed (LF) octet pair, but also offers that implementations "MAY" accept just a Line Feed octet as a separator.HttpDecoderConfigsetTrailersFactory(HttpHeadersFactory trailersFactory)Set theHttpHeadersFactoryused to create HTTP trailers.HttpDecoderConfigsetValidateHeaders(boolean validateHeaders)Set whether header validation should be enabled or not.
-
-
-
Method Detail
-
getInitialBufferSize
public int getInitialBufferSize()
-
setInitialBufferSize
public HttpDecoderConfig setInitialBufferSize(int initialBufferSize)
Set the initial size of the temporary buffer used when parsing the lines of the HTTP headers.- Parameters:
initialBufferSize- The buffer size in bytes.- Returns:
- This decoder config.
-
getMaxInitialLineLength
public int getMaxInitialLineLength()
-
setMaxInitialLineLength
public HttpDecoderConfig setMaxInitialLineLength(int maxInitialLineLength)
Set the maximum length of the first line of the HTTP header. This limits how much memory Netty will use when parsed the initial HTTP header line. You would typically set this to the same value assetMaxHeaderSize(int).- Parameters:
maxInitialLineLength- The maximum length, in bytes.- Returns:
- This decoder config.
-
getMaxHeaderSize
public int getMaxHeaderSize()
-
setMaxHeaderSize
public HttpDecoderConfig setMaxHeaderSize(int maxHeaderSize)
Set the maximum line length of header lines. This limits how much memory Netty will use when parsing HTTP header key-value pairs. The limit applies to the sum of all the headers, so it applies equally to many short header-lines, or fewer but longer header lines.You would typically set this to the same value as
setMaxInitialLineLength(int).- Parameters:
maxHeaderSize- The maximum length, in bytes.- Returns:
- This decoder config.
-
getMaxChunkSize
public int getMaxChunkSize()
-
setMaxChunkSize
public HttpDecoderConfig setMaxChunkSize(int maxChunkSize)
Set the maximum chunk size. HTTP requests and responses can be quite large, in which case it's better to process the data as a stream of chunks. This sets the limit, in bytes, at which Netty will send a chunk down the pipeline.- Parameters:
maxChunkSize- The maximum chunk size, in bytes.- Returns:
- This decoder config.
-
isChunkedSupported
public boolean isChunkedSupported()
-
setChunkedSupported
public HttpDecoderConfig setChunkedSupported(boolean chunkedSupported)
Set whetherTransfer-Encoding: Chunkedshould be supported.- Parameters:
chunkedSupported- iffalse, then aTransfer-Encoding: Chunkedheader will produce an error, instead of a stream of chunks.- Returns:
- This decoder config.
-
isAllowPartialChunks
public boolean isAllowPartialChunks()
-
setAllowPartialChunks
public HttpDecoderConfig setAllowPartialChunks(boolean allowPartialChunks)
Set whether chunks can be split into multiple messages, if their chunk size exceeds the size of the input buffer.- Parameters:
allowPartialChunks- set tofalseto only allow sending whole chunks down the pipeline.- Returns:
- This decoder config.
-
getHeadersFactory
public HttpHeadersFactory getHeadersFactory()
-
setHeadersFactory
public HttpDecoderConfig setHeadersFactory(HttpHeadersFactory headersFactory)
Set theHttpHeadersFactoryto use when creating new HTTP headers objects. The default headers factory isDefaultHttpHeadersFactory.headersFactory().For the purpose of
clone(), it is assumed that the factory is either immutable, or can otherwise be shared across different decoders and decoder configs.- Parameters:
headersFactory- The header factory to use.- Returns:
- This decoder config.
-
isAllowDuplicateContentLengths
public boolean isAllowDuplicateContentLengths()
-
setAllowDuplicateContentLengths
public HttpDecoderConfig setAllowDuplicateContentLengths(boolean allowDuplicateContentLengths)
Set whether more than oneContent-Lengthheader is allowed. You usually want to disallow this (which is the default) as multipleContent-Lengthheaders can indicate a request- or response-splitting attack.- Parameters:
allowDuplicateContentLengths- set totrueto allow multiple content length headers.- Returns:
- This decoder config.
-
setValidateHeaders
public HttpDecoderConfig setValidateHeaders(boolean validateHeaders)
Set whether header validation should be enabled or not. This works by changing the configured header factory and trailer factory.You usually want header validation enabled (which is the default) in order to prevent request-/response-splitting attacks.
- Parameters:
validateHeaders- set tofalseto disable header validation.- Returns:
- This decoder config.
-
getTrailersFactory
public HttpHeadersFactory getTrailersFactory()
-
setTrailersFactory
public HttpDecoderConfig setTrailersFactory(HttpHeadersFactory trailersFactory)
Set theHttpHeadersFactoryused to create HTTP trailers. This differs fromsetHeadersFactory(HttpHeadersFactory)in that trailers have different validation requirements. The default trailer factory isDefaultHttpHeadersFactory.headersFactory().For the purpose of
clone(), it is assumed that the factory is either immutable, or can otherwise be shared across different decoders and decoder configs.- Parameters:
trailersFactory- The headers factory to use for creating trailers.- Returns:
- This decoder config.
-
isStrictLineParsing
public boolean isStrictLineParsing()
-
setStrictLineParsing
public HttpDecoderConfig setStrictLineParsing(boolean strictLineParsing)
The RFC 9112 specification for the HTTP protocol says that the initial start-line, and the following header field-lines, must be separated by a Carriage Return (CR) and Line Feed (LF) octet pair, but also offers that implementations "MAY" accept just a Line Feed octet as a separator.Parsing leniencies can increase compatibility with a wider range of implementations, but can also cause security vulnerabilities, when multiple systems disagree on the meaning of leniently parsed messages.
When strict line parsing is enabled (
true), then Netty will enforce that start- and header field-lines MUST be separated by a CR LF octet pair, and will produce messagas with failedDecoderResults.When strict line parsing is disabled (
false), then Netty will accept lone LF octets as line seperators for the start- and header field-lines.See RFC 9112 Section 2.1.
- Parameters:
strictLineParsing- Whether strict line parsing should be enabled (true), or not (false).- Returns:
- This decoder config.
-
clone
public HttpDecoderConfig clone()
- Overrides:
clonein classjava.lang.Object
-
-