Top Description Inners Fields Constructors Methods
io.netty.handler.codec.http

public final Class HttpServerCodec

extends CombinedChannelDuplexHandler<HttpRequestDecoder, HttpResponseEncoder>
implements SourceCodec
Class Inheritance
All Implemented Interfaces
io.netty.handler.codec.http.HttpServerUpgradeHandler.SourceCodec
Imports
io.netty.buffer.ByteBuf, io.netty.channel.ChannelHandlerContext, .CombinedChannelDuplexHandler, java.util.ArrayDeque, .List, .Queue

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
HttpClientCodec

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private final Queue<HttpMethod>
queue

A queue that is used for correlating a request and a response.

Constructor Summary

AccessConstructor and Description
public
HttpServerCodec()

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

public
HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize)

Creates a new instance with the specified decoder options.

public
HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders)

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

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

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

Deprecated Prefer the HttpServerCodec(HttpDecoderConfig) constructor, to always enable header validation.
Creates a new instance with the specified decoder options.
public
HttpServerCodec(HttpDecoderConfig config)

Creates a new instance with the specified decoder configuration.

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from io.netty.channel.CombinedChannelDuplexHandler:
bindchannelActivechannelInactivechannelReadchannelReadCompletechannelRegisteredchannelUnregisteredchannelWritabilityChangedcloseconnectderegisterdisconnectexceptionCaughtflushhandlerAddedhandlerRemovedinboundHandlerinitoutboundHandlerreadremoveInboundHandlerremoveOutboundHandleruserEventTriggeredwrite

Field Detail

queueback to summary
private final Queue<HttpMethod> queue

A queue that is used for correlating a request and a response.

Constructor Detail

HttpServerCodecback to summary
public HttpServerCodec()

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

HttpServerCodecback to summary
public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize)

Creates a new instance with the specified decoder options.

HttpServerCodecback to summary
public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders)

Deprecated

Prefer the HttpServerCodec(HttpDecoderConfig) constructor, to always enable header validation.

Creates a new instance with the specified decoder options.

Annotations
@Deprecated
HttpServerCodecback to summary
public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, int initialBufferSize)

Deprecated

Prefer the HttpServerCodec(HttpDecoderConfig) constructor, to always enable header validation.

Creates a new instance with the specified decoder options.

Annotations
@Deprecated
HttpServerCodecback to summary
public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, int initialBufferSize, boolean allowDuplicateContentLengths)

Deprecated

Prefer the HttpServerCodec(HttpDecoderConfig) constructor, to always enable header validation.

Creates a new instance with the specified decoder options.

Annotations
@Deprecated
HttpServerCodecback to summary
public HttpServerCodec(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders, int initialBufferSize, boolean allowDuplicateContentLengths, boolean allowPartialChunks)

Deprecated

Prefer the HttpServerCodec(HttpDecoderConfig) constructor, to always enable header validation.

Creates a new instance with the specified decoder options.

Annotations
@Deprecated
HttpServerCodecback to summary
public HttpServerCodec(HttpDecoderConfig config)

Creates a new instance with the specified decoder configuration.

Method Detail

upgradeFromback to summary
public void upgradeFrom(ChannelHandlerContext ctx)

Implements io.netty.handler.codec.http.HttpServerUpgradeHandler.SourceCodec.upgradeFrom.

Upgrades to another protocol from HTTP. Removes the HttpRequestDecoder and HttpResponseEncoder from the pipeline.

Annotations
@Override
io.netty.handler.codec.http back to summary

private final Class HttpServerCodec.HttpServerRequestDecoder

extends HttpRequestDecoder
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
decode(ChannelHandlerContext ctx, ByteBuf
the ByteBuf from which to read data
buffer
,
List<Object>
the List to which decoded messages should be added
out
)

Overrides io.netty.handler.codec.http.HttpObjectDecoder.decode.

Decode the from one ByteBuf to an other.
Inherited from io.netty.handler.codec.http.HttpRequestDecoder:
createInvalidMessagecreateMessageisContentAlwaysEmptyisDecodingRequestsplitFirstWordInitialLinesplitHeaderNamesplitThirdWordInitialLine

Constructor Detail

HttpServerRequestDecoderback to summary
pack-priv HttpServerRequestDecoder(HttpDecoderConfig config)

Method Detail

decodeback to summary
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception

Overrides io.netty.handler.codec.http.HttpObjectDecoder.decode.

Doc from io.netty.handler.codec.ByteToMessageDecoder.decode.

Decode the from one ByteBuf to an other. This method will be called till either the input ByteBuf has nothing to read when return from this method or till nothing was read from the input ByteBuf.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this ByteToMessageDecoder belongs to

buffer:ByteBuf

the ByteBuf from which to read data

out:List<Object>

the List to which decoded messages should be added

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
io.netty.handler.codec.http back to summary

private final Class HttpServerCodec.HttpServerResponseEncoder

extends HttpResponseEncoder
Class Inheritance

Field Summary

Modifier and TypeField and Description
private HttpMethod

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected boolean
isContentAlwaysEmpty(HttpResponse
the message to test
msg
)

Overrides io.netty.handler.codec.http.HttpResponseEncoder.isContentAlwaysEmpty.

Determine whether a message has a content or not.
protected void
sanitizeHeadersBeforeEncode(HttpResponse msg, boolean isAlwaysEmpty)

Overrides io.netty.handler.codec.http.HttpResponseEncoder.sanitizeHeadersBeforeEncode.

Allows to sanitize headers of the message before encoding these.
Inherited from io.netty.handler.codec.http.HttpResponseEncoder:
acceptOutboundMessageencodeInitialLine

Field Detail

methodback to summary
private HttpMethod method

Constructor Detail

HttpServerResponseEncoderback to summary
private HttpServerResponseEncoder()

Method Detail

isContentAlwaysEmptyback to summary
protected boolean isContentAlwaysEmpty(HttpResponse msg)

Overrides io.netty.handler.codec.http.HttpResponseEncoder.isContentAlwaysEmpty.

Doc from io.netty.handler.codec.http.HttpObjectEncoder.isContentAlwaysEmpty.

Determine whether a message has a content or not. Some message may have headers indicating a content without having an actual content, e.g the response to an HEAD or CONNECT request.

Parameters
msg:HttpResponse

the message to test

Returns:boolean

true to signal the message has no content

Annotations
@Override
sanitizeHeadersBeforeEncodeback to summary
protected void sanitizeHeadersBeforeEncode(HttpResponse msg, boolean isAlwaysEmpty)

Overrides io.netty.handler.codec.http.HttpResponseEncoder.sanitizeHeadersBeforeEncode.

Doc from io.netty.handler.codec.http.HttpObjectEncoder.sanitizeHeadersBeforeEncode.

Allows to sanitize headers of the message before encoding these.

Annotations
@Override