Class HttpClientCodec

All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler, HttpClientUpgradeHandler.SourceCodec

A combination of HttpRequestEncoder and HttpResponseDecoder which enables easier client side HTTP implementation. HttpClientCodec provides additional state management for HEAD and CONNECT requests, which HttpResponseDecoder lacks. Please refer to HttpResponseDecoder to learn what additional state management needs to be done for HEAD and CONNECT and why HttpResponseDecoder can not handle it by itself.

If the Channel is closed and there are missing responses, a PrematureChannelClosureException is thrown.

Header Validation

It is recommended to always enable header validation.

Without header validation, your system can become vulnerable to CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting') .

This recommendation stands even when both peers in the HTTP exchange are trusted, as it helps with defence-in-depth.

See Also:
  • Field Details

    • DEFAULT_FAIL_ON_MISSING_RESPONSE

      public static final boolean DEFAULT_FAIL_ON_MISSING_RESPONSE
      See Also:
    • DEFAULT_PARSE_HTTP_AFTER_CONNECT_REQUEST

      public static final boolean DEFAULT_PARSE_HTTP_AFTER_CONNECT_REQUEST
      See Also:
    • queue

      private final Queue<HttpMethod> queue
      A queue that is used for correlating a request and a response.
    • parseHttpAfterConnectRequest

      private final boolean parseHttpAfterConnectRequest
    • done

      private boolean done
      If true, decoding stops (i.e. pass-through)
    • requestResponseCounter

      private final AtomicLong requestResponseCounter
    • failOnMissingResponse

      private final boolean failOnMissingResponse
  • Constructor Details

    • HttpClientCodec

      public HttpClientCodec()
      Creates a new instance with the default decoder options (maxInitialLineLength (4096), maxHeaderSize (8192), and maxChunkSize (8192)).
    • HttpClientCodec

      public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize)
      Creates a new instance with the specified decoder options.
    • HttpClientCodec

      public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse)
      Creates a new instance with the specified decoder options.
    • HttpClientCodec

      @Deprecated public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders)
      Deprecated.
      Prefer the HttpClientCodec(int, int, int, boolean) constructor, to always enable header validation.
      Creates a new instance with the specified decoder options.
    • HttpClientCodec

      @Deprecated public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, boolean parseHttpAfterConnectRequest)
      Deprecated.
      Prefer the HttpClientCodec(HttpDecoderConfig, boolean, boolean) constructor, to always enable header validation.
      Creates a new instance with the specified decoder options.
    • HttpClientCodec

      @Deprecated public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize)
      Deprecated.
      Prefer the HttpClientCodec(HttpDecoderConfig, boolean, boolean) constructor, to always enable header validation.
      Creates a new instance with the specified decoder options.
    • HttpClientCodec

      @Deprecated public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest)
      Deprecated.
      Prefer the HttpClientCodec(HttpDecoderConfig, boolean, boolean) constructor, to always enable header validation.
      Creates a new instance with the specified decoder options.
    • HttpClientCodec

      @Deprecated public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest, boolean allowDuplicateContentLengths)
      Deprecated.
      Prefer the HttpClientCodec(HttpDecoderConfig, boolean, boolean) constructor, to always enable header validation.
      Creates a new instance with the specified decoder options.
    • HttpClientCodec

      @Deprecated public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest, boolean allowDuplicateContentLengths, boolean allowPartialChunks)
      Deprecated.
      Prefer the HttpClientCodec(HttpDecoderConfig, boolean, boolean) constructor, to always enable header validation.
      Creates a new instance with the specified decoder options.
    • HttpClientCodec

      public HttpClientCodec(HttpDecoderConfig config, boolean parseHttpAfterConnectRequest, boolean failOnMissingResponse)
      Creates a new instance with the specified decoder options.
  • Method Details