Package io.netty.handler.codec.http
Class HttpServerCodec
- All Implemented Interfaces:
ChannelHandler
,ChannelInboundHandler
,ChannelOutboundHandler
,HttpServerUpgradeHandler.SourceCodec
public final class HttpServerCodec
extends CombinedChannelDuplexHandler<HttpRequestDecoder,HttpResponseEncoder>
implements HttpServerUpgradeHandler.SourceCodec
A combination of
HttpRequestDecoder
and HttpResponseEncoder
which enables easier server side HTTP implementation.
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 ClassesModifier and TypeClassDescriptionprivate final class
private final class
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Queue
<HttpMethod> A queue that is used for correlating a request and a response. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with the default decoder options (maxInitialLineLength (4096)
,maxHeaderSize (8192)
, andmaxChunkSize (8192)
).HttpServerCodec
(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) Creates a new instance with the specified decoder options.HttpServerCodec
(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders) Deprecated.HttpServerCodec
(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, int initialBufferSize) Deprecated.Prefer theHttpServerCodec(HttpDecoderConfig)
constructor, to always enable header validation.HttpServerCodec
(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, int initialBufferSize, boolean allowDuplicateContentLengths) Deprecated.Prefer theHttpServerCodec(HttpDecoderConfig)
constructor, to always enable header validation.HttpServerCodec
(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, int initialBufferSize, boolean allowDuplicateContentLengths, boolean allowPartialChunks) Deprecated.Prefer theHttpServerCodec(HttpDecoderConfig)
constructor, to always enable header validation.HttpServerCodec
(HttpDecoderConfig config) Creates a new instance with the specified decoder configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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, write
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
Field Details
-
queue
A queue that is used for correlating a request and a response.
-
-
Constructor Details
-
HttpServerCodec
public HttpServerCodec()Creates a new instance with the default decoder options (maxInitialLineLength (4096)
,maxHeaderSize (8192)
, andmaxChunkSize (8192)
). -
HttpServerCodec
public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) Creates a new instance with the specified decoder options. -
HttpServerCodec
@Deprecated public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders) Deprecated.Prefer theHttpServerCodec(HttpDecoderConfig)
constructor, to always enable header validation.Creates a new instance with the specified decoder options. -
HttpServerCodec
@Deprecated public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, int initialBufferSize) Deprecated.Prefer theHttpServerCodec(HttpDecoderConfig)
constructor, to always enable header validation.Creates a new instance with the specified decoder options. -
HttpServerCodec
@Deprecated public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, int initialBufferSize, boolean allowDuplicateContentLengths) Deprecated.Prefer theHttpServerCodec(HttpDecoderConfig)
constructor, to always enable header validation.Creates a new instance with the specified decoder options. -
HttpServerCodec
@Deprecated public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, int initialBufferSize, boolean allowDuplicateContentLengths, boolean allowPartialChunks) Deprecated.Prefer theHttpServerCodec(HttpDecoderConfig)
constructor, to always enable header validation.Creates a new instance with the specified decoder options. -
HttpServerCodec
Creates a new instance with the specified decoder configuration.
-
-
Method Details
-
upgradeFrom
Upgrades to another protocol from HTTP. Removes theHttpRequestDecoder
andHttpResponseEncoder
from the pipeline.- Specified by:
upgradeFrom
in interfaceHttpServerUpgradeHandler.SourceCodec
-
HttpServerCodec(HttpDecoderConfig)
constructor, to always enable header validation.