Class HttpDecoderConfig

java.lang.Object
io.netty.handler.codec.http.HttpDecoderConfig
All Implemented Interfaces:
Cloneable

public final class HttpDecoderConfig extends Object implements Cloneable
A configuration object for specifying the behaviour of HttpObjectDecoder and its subclasses.

The HttpDecoderConfig objects are mutable to reduce allocation, but also Cloneable in case a defensive copy is needed.

  • Field Details

    • maxChunkSize

      private int maxChunkSize
    • chunkedSupported

      private boolean chunkedSupported
    • allowPartialChunks

      private boolean allowPartialChunks
    • headersFactory

      private HttpHeadersFactory headersFactory
    • trailersFactory

      private HttpHeadersFactory trailersFactory
    • allowDuplicateContentLengths

      private boolean allowDuplicateContentLengths
    • maxInitialLineLength

      private int maxInitialLineLength
    • maxHeaderSize

      private int maxHeaderSize
    • initialBufferSize

      private int initialBufferSize
  • Constructor Details

    • HttpDecoderConfig

      public HttpDecoderConfig()
  • Method Details

    • 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 as setMaxHeaderSize(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. 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 whether Transfer-Encoding: Chunked should be supported.
      Parameters:
      chunkedSupported - if false, then a Transfer-Encoding: Chunked header 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 to false to only allow sending whole chunks down the pipeline.
      Returns:
      This decoder config.
    • getHeadersFactory

      public HttpHeadersFactory getHeadersFactory()
    • setHeadersFactory

      public HttpDecoderConfig setHeadersFactory(HttpHeadersFactory headersFactory)
      Set the HttpHeadersFactory to use when creating new HTTP headers objects. The default headers factory is DefaultHttpHeadersFactory.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 one Content-Length header is allowed. You usually want to disallow this (which is the default) as multiple Content-Length headers can indicate a request- or response-splitting attack.
      Parameters:
      allowDuplicateContentLengths - set to true to 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 to false to disable header validation.
      Returns:
      This decoder config.
    • getTrailersFactory

      public HttpHeadersFactory getTrailersFactory()
    • setTrailersFactory

      public HttpDecoderConfig setTrailersFactory(HttpHeadersFactory trailersFactory)
      Set the HttpHeadersFactory used to create HTTP trailers. This differs from setHeadersFactory(HttpHeadersFactory) in that trailers have different validation requirements. The default trailer factory is DefaultHttpHeadersFactory.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.
    • clone

      public HttpDecoderConfig clone()
      Overrides:
      clone in class Object