public final class HttpClientCodec extends CombinedChannelDuplexHandler<HttpResponseDecoder,HttpRequestEncoder> implements HttpClientUpgradeHandler.SourceCodec
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.
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.
HttpServerCodec
ChannelHandler.Sharable
限定符和类型 | 字段和说明 |
---|---|
static boolean |
DEFAULT_FAIL_ON_MISSING_RESPONSE |
static boolean |
DEFAULT_PARSE_HTTP_AFTER_CONNECT_REQUEST |
构造器和说明 |
---|
HttpClientCodec()
Creates a new instance with the default decoder options
(
maxInitialLineLength (4096) , maxHeaderSize (8192) , and
maxChunkSize (8192) ). |
HttpClientCodec(HttpDecoderConfig config,
boolean parseHttpAfterConnectRequest,
boolean failOnMissingResponse)
Creates a new instance with the specified decoder options.
|
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)
已过时。
Prefer the
HttpClientCodec(int, int, int, boolean) constructor,
to always enable header validation. |
HttpClientCodec(int maxInitialLineLength,
int maxHeaderSize,
int maxChunkSize,
boolean failOnMissingResponse,
boolean validateHeaders,
boolean parseHttpAfterConnectRequest)
已过时。
Prefer the
HttpClientCodec(HttpDecoderConfig, boolean, boolean) constructor,
to always enable header validation. |
HttpClientCodec(int maxInitialLineLength,
int maxHeaderSize,
int maxChunkSize,
boolean failOnMissingResponse,
boolean validateHeaders,
int initialBufferSize)
已过时。
Prefer the
HttpClientCodec(HttpDecoderConfig, boolean, boolean) constructor,
to always enable header validation. |
HttpClientCodec(int maxInitialLineLength,
int maxHeaderSize,
int maxChunkSize,
boolean failOnMissingResponse,
boolean validateHeaders,
int initialBufferSize,
boolean parseHttpAfterConnectRequest)
已过时。
Prefer the
HttpClientCodec(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)
已过时。
Prefer the
HttpClientCodec(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)
已过时。
Prefer the
HttpClientCodec(HttpDecoderConfig, boolean, boolean)
constructor, to always enable header validation. |
限定符和类型 | 方法和说明 |
---|---|
boolean |
isSingleDecode() |
void |
prepareUpgradeFrom(ChannelHandlerContext ctx)
Prepares to upgrade to another protocol from HTTP.
|
void |
setSingleDecode(boolean singleDecode) |
void |
upgradeFrom(ChannelHandlerContext ctx)
Upgrades to another protocol from HTTP.
|
bind, channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, handlerAdded, handlerRemoved, inboundHandler, init, outboundHandler, read, removeInboundHandler, removeOutboundHandler, userEventTriggered, write
ensureNotSharable, isSharable
public static final boolean DEFAULT_FAIL_ON_MISSING_RESPONSE
public static final boolean DEFAULT_PARSE_HTTP_AFTER_CONNECT_REQUEST
public HttpClientCodec()
maxInitialLineLength (4096)
, maxHeaderSize (8192)
, and
maxChunkSize (8192)
).public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize)
public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse)
@Deprecated public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders)
HttpClientCodec(int, int, int, boolean)
constructor,
to always enable header validation.@Deprecated public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, boolean parseHttpAfterConnectRequest)
HttpClientCodec(HttpDecoderConfig, boolean, boolean)
constructor,
to always enable header validation.@Deprecated public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize)
HttpClientCodec(HttpDecoderConfig, boolean, boolean)
constructor,
to always enable header validation.@Deprecated public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest)
HttpClientCodec(HttpDecoderConfig, boolean, boolean)
constructor,
to always enable header validation.@Deprecated public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest, boolean allowDuplicateContentLengths)
HttpClientCodec(HttpDecoderConfig, boolean, boolean)
constructor,
to always enable header validation.@Deprecated public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest, boolean allowDuplicateContentLengths, boolean allowPartialChunks)
HttpClientCodec(HttpDecoderConfig, boolean, boolean)
constructor, to always enable header validation.public HttpClientCodec(HttpDecoderConfig config, boolean parseHttpAfterConnectRequest, boolean failOnMissingResponse)
public void prepareUpgradeFrom(ChannelHandlerContext ctx)
Encoder
.public void upgradeFrom(ChannelHandlerContext ctx)
Decoder
and Encoder
from
the pipeline.public void setSingleDecode(boolean singleDecode)
public boolean isSingleDecode()