Class HttpServerCodec
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.netty.channel.CombinedChannelDuplexHandler<HttpRequestDecoder, HttpResponseEncoder>
io.netty.handler.codec.http.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 classes/interfaces inherited from interface ChannelHandler
ChannelHandler.SharableModifier and TypeInterfaceDescriptionstatic @interfaceIndicates that the same instance of the annotatedChannelHandlercan be added to one or moreChannelPipelines multiple times without a race condition. -
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.HttpServerCodec(HttpDecoderConfig config, int maxPipelineDepth) Creates a new instance with the specified decoder configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidUpgrades to another protocol from HTTP.Methods inherited from class CombinedChannelDuplexHandler
bind, channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, handlerAdded, handlerRemoved, inboundHandler, init, outboundHandler, read, removeInboundHandler, removeOutboundHandler, userEventTriggered, writeModifier and TypeMethodDescriptionvoidbind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) CallsChannelOutboundInvoker.bind(SocketAddress, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelActive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidchannelRead(ChannelHandlerContext ctx, Object msg) CallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelRegistered()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelUnregistered()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelWritabilityChanged()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidclose(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.close(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidconnect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) CallsChannelOutboundInvoker.connect(SocketAddress, SocketAddress, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidderegister(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.deregister(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voiddisconnect(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.disconnect(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidexceptionCaught(ChannelHandlerContext ctx, Throwable cause) CallsChannelHandlerContext.fireExceptionCaught(Throwable)to forward to the nextChannelHandlerin theChannelPipeline.voidCallsChannelHandlerContext.flush()to forward to the nextChannelOutboundHandlerin theChannelPipeline.voidDo nothing by default, sub-classes may override this method.voidDo nothing by default, sub-classes may override this method.protected final HttpRequestDecoderprotected final voidinit(HttpRequestDecoder inboundHandler, HttpResponseEncoder outboundHandler) Initialized this handler with the specified handlers.protected final HttpResponseEncodervoidCallsChannelHandlerContext.read()to forward to the nextChannelOutboundHandlerin theChannelPipeline.final voidRemoves theChannelInboundHandlerthat was combined in thisCombinedChannelDuplexHandler.final voidRemoves theChannelOutboundHandlerthat was combined in thisCombinedChannelDuplexHandler.voiduserEventTriggered(ChannelHandlerContext ctx, Object evt) CallsChannelHandlerContext.fireUserEventTriggered(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.voidwrite(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) CallsChannelOutboundInvoker.write(Object, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.Methods inherited from class ChannelHandlerAdapter
ensureNotSharable, isSharableModifier and TypeMethodDescriptionprotected voidbooleanReturntrueif the implementation isChannelHandler.Sharableand so can be added to differentChannelPipelines.
-
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. -
HttpServerCodec
Creates a new instance with the specified decoder configuration.- Parameters:
config- the decoder configuration.maxPipelineDepth- the maximum number of requests that may be decoded while awaiting the corresponding responses to be written, before decoding of further requests is rejected with anIllegalStateException.
-
-
Method Details
-
upgradeFrom
Upgrades to another protocol from HTTP. Removes theHttpRequestDecoderandHttpResponseEncoderfrom the pipeline.- Specified by:
upgradeFromin interfaceHttpServerUpgradeHandler.SourceCodec
-
HttpServerCodec(HttpDecoderConfig)constructor, to always enable header validation.