Package io.netty.handler.codec.http
Class HttpClientCodec
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.netty.channel.CombinedChannelDuplexHandler<HttpResponseDecoder,HttpRequestEncoder>
io.netty.handler.codec.http.HttpClientCodec
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,io.netty.channel.ChannelOutboundHandler,HttpClientUpgradeHandler.SourceCodec
public final class HttpClientCodec
extends io.netty.channel.CombinedChannelDuplexHandler<HttpResponseDecoder,HttpRequestEncoder>
implements 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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanstatic final boolean -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with the default decoder options (maxInitialLineLength (4096),maxHeaderSize (8192), andmaxChunkSize (8192)).HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) Creates a new instance with the specified decoder options.HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse) Creates a new instance with the specified decoder options.HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders) Deprecated.HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, boolean parseHttpAfterConnectRequest) Deprecated.Prefer theHttpClientCodec(HttpDecoderConfig, boolean, boolean)constructor, to always enable header validation.HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize) Deprecated.Prefer theHttpClientCodec(HttpDecoderConfig, boolean, boolean)constructor, to always enable header validation.HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest) Deprecated.Prefer theHttpClientCodec(HttpDecoderConfig, boolean, boolean)constructor, to always enable header validation.HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest, boolean allowDuplicateContentLengths) Deprecated.Prefer theHttpClientCodec(HttpDecoderConfig, boolean, boolean)constructor, to always enable header validation.HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest, boolean allowDuplicateContentLengths, boolean allowPartialChunks) Deprecated.Prefer theHttpClientCodec(HttpDecoderConfig, boolean, boolean)constructor, to always enable header validation.HttpClientCodec(HttpDecoderConfig config, boolean parseHttpAfterConnectRequest, boolean failOnMissingResponse) Creates a new instance with the specified decoder options. -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidprepareUpgradeFrom(io.netty.channel.ChannelHandlerContext ctx) Prepares to upgrade to another protocol from HTTP.voidsetSingleDecode(boolean singleDecode) voidupgradeFrom(io.netty.channel.ChannelHandlerContext ctx) Upgrades to another protocol from HTTP.Methods inherited from class io.netty.channel.CombinedChannelDuplexHandler
bind, channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, handlerAdded, handlerRemoved, inboundHandler, init, outboundHandler, read, removeInboundHandler, removeOutboundHandler, userEventTriggered, writeMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
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:
-
-
Constructor Details
-
HttpClientCodec
public HttpClientCodec()Creates a new instance with the default decoder options (maxInitialLineLength (4096),maxHeaderSize (8192), andmaxChunkSize (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 theHttpClientCodec(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 theHttpClientCodec(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 theHttpClientCodec(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 theHttpClientCodec(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 theHttpClientCodec(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 theHttpClientCodec(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
-
prepareUpgradeFrom
public void prepareUpgradeFrom(io.netty.channel.ChannelHandlerContext ctx) Prepares to upgrade to another protocol from HTTP. Disables theHttpClientCodec.Encoder.- Specified by:
prepareUpgradeFromin interfaceHttpClientUpgradeHandler.SourceCodec
-
upgradeFrom
public void upgradeFrom(io.netty.channel.ChannelHandlerContext ctx) Upgrades to another protocol from HTTP. Removes theHttpClientCodec.DecoderandHttpClientCodec.Encoderfrom the pipeline.- Specified by:
upgradeFromin interfaceHttpClientUpgradeHandler.SourceCodec
-
setSingleDecode
public void setSingleDecode(boolean singleDecode) -
isSingleDecode
public boolean isSingleDecode()
-
HttpClientCodec(int, int, int, boolean)constructor, to always enable header validation.