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

public Class HttpObjectAggregator

extends MessageAggregator<HttpObject, HttpMessage, HttpContent, FullHttpMessage>
Class Inheritance
Known Direct Subclasses
io.netty.handler.codec.http.HttpClientUpgradeHandler, io.netty.handler.codec.http.HttpServerUpgradeHandler
Imports
io.netty.buffer.ByteBuf, .Unpooled, io.netty.channel.ChannelFuture, .ChannelFutureListener, .ChannelHandler, .ChannelHandlerContext, .ChannelPipeline, io.netty.handler.codec.DecoderResult, .MessageAggregator, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory

A ChannelHandler that aggregates an HttpMessage and its following HttpContents into a single FullHttpRequest or FullHttpResponse (depending on if it used to handle requests or responses) with no following HttpContents. It is useful when you don't want to take care of HTTP messages whose transfer encoding is 'chunked'. Insert this handler after HttpResponseDecoder in the ChannelPipeline if being used to handle responses, or after HttpRequestDecoder and HttpResponseEncoder in the ChannelPipeline if being used to handle requests.
 ChannelPipeline p = ...;
 ...
 p.addLast("decoder", new HttpRequestDecoder());
 p.addLast("encoder", new HttpResponseEncoder());
 p.addLast("aggregator", new HttpObjectAggregator(1048576));
 ...
 p.addLast("handler", new HttpRequestHandler());
 

For convenience, consider putting a HttpServerCodec before the HttpObjectAggregator as it functions as both a HttpRequestDecoder and a HttpResponseEncoder.

Be aware that HttpObjectAggregator may end up sending a HttpResponse:
Response Status Condition When Sent
100 Continue A '100-continue' expectation is received and the 'content-length' doesn't exceed maxContentLength
417 Expectation Failed A '100-continue' expectation is received and the 'content-length' exceeds maxContentLength
413 Request Entity Too Large Either the 'content-length' or the bytes received so far exceed maxContentLength
See Also
FullHttpRequest, FullHttpResponse, HttpResponseDecoder, HttpServerCodec

Nested and Inner Type Summary

Modifier and TypeClass and Description
private abstract static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private final boolean
private static final FullHttpResponse
private static final FullHttpResponse
private static final InternalLogger
private static final FullHttpResponse
private static final FullHttpResponse

Constructor Summary

AccessConstructor and Description
public
HttpObjectAggregator(int
the maximum length of the aggregated content in bytes. If the length of the aggregated content exceeds this value, handleOversizedMessage(ChannelHandlerContext, HttpMessage) will be called.
maxContentLength
)

Creates a new instance.

public
HttpObjectAggregator(int
the maximum length of the aggregated content in bytes. If the length of the aggregated content exceeds this value, handleOversizedMessage(ChannelHandlerContext, HttpMessage) will be called.
maxContentLength
,
boolean
If a 100-continue response is detected but the content length is too large then true means close the connection. otherwise the connection will remain open and data will be consumed and discarded until the next request is received.
closeOnExpectationFailed
)

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
protected void
aggregate(FullHttpMessage aggregated, HttpContent content)

Overrides io.netty.handler.codec.MessageAggregator.aggregate.

Transfers the information provided by the specified content message to the specified aggregated message.
protected FullHttpMessage
beginAggregation(HttpMessage start, ByteBuf content)

Implements abstract io.netty.handler.codec.MessageAggregator.beginAggregation.

Creates a new aggregated message from the specified start message and the specified content.
protected boolean
private static Object
continueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline)

protected void
finishAggregation(FullHttpMessage aggregated)

Overrides io.netty.handler.codec.MessageAggregator.finishAggregation.

Invoked when the specified aggregated message is about to be passed to the next handler in the pipeline.
protected void
handleOversizedMessage(final ChannelHandlerContext ctx, HttpMessage
the accumulated message up to this point, whose type is S or O
oversized
)

Overrides io.netty.handler.codec.MessageAggregator.handleOversizedMessage.

Invoked when an incoming request exceeds the maximum content length.
protected boolean
ignoreContentAfterContinueResponse(Object msg)

Implements abstract io.netty.handler.codec.MessageAggregator.ignoreContentAfterContinueResponse.

Determine if all objects for the current request/response should be ignored or not.
protected boolean
isAggregated(HttpObject msg)

Implements abstract io.netty.handler.codec.MessageAggregator.isAggregated.

Returns true if and only if the specified message is already aggregated.
protected boolean
isContentLengthInvalid(HttpMessage
The message which may indicate the content length.
start
,
int
The maximum allowed content length.
maxContentLength
)

Implements abstract io.netty.handler.codec.MessageAggregator.isContentLengthInvalid.

Determine if the message start's content length is known, and if it greater than maxContentLength.
protected boolean
isContentMessage(HttpObject msg)

Implements abstract io.netty.handler.codec.MessageAggregator.isContentMessage.

Returns true if and only if the specified message is a content message.
protected boolean
isLastContentMessage(HttpContent msg)

Implements abstract io.netty.handler.codec.MessageAggregator.isLastContentMessage.

Returns true if and only if the specified message is the last content message.
protected boolean
isStartMessage(HttpObject msg)

Implements abstract io.netty.handler.codec.MessageAggregator.isStartMessage.

Returns true if and only if the specified message is a start message.
protected Object
newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline)

Implements abstract io.netty.handler.codec.MessageAggregator.newContinueResponse.

Returns the 'continue response' for the specified start message if necessary.
Inherited from io.netty.handler.codec.MessageAggregator:
acceptInboundMessagechannelInactivechannelReadCompletectxdecodehandlerAddedhandlerRemovedisHandlingOversizedMessagemaxContentLengthmaxCumulationBufferComponentssetMaxCumulationBufferComponents