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

public Class HttpObjectAggregator<C extends HttpContent<C>>

extends MessageAggregator<HttpObject, HttpMessage, HttpContent<C extends HttpContent<C>>, FullHttpMessage<?>>
Class Inheritance
Known Direct Subclasses
io.netty5.handler.codec.http.HttpServerUpgradeHandler, io.netty5.handler.codec.http.HttpClientUpgradeHandler
Imports
io.netty5.buffer.Buffer, .BufferAllocator, .CompositeBuffer, io.netty5.util.Send, io.netty5.channel.ChannelHandler, .ChannelHandlerContext, .ChannelPipeline, io.netty5.handler.codec.DecoderResult, .MessageAggregator, io.netty5.handler.codec.http.headers.HttpHeaders, io.netty5.util.concurrent.Future, io.netty5.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
private static class

Field Summary

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

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, Object) 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, Object) 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(BufferAllocator allocator, FullHttpMessage<?> aggregated, HttpContent<C> content)

Implements abstract io.netty5.handler.codec.MessageAggregator.aggregate.

Aggregated the passed content in the passed aggregate.
protected FullHttpMessage<?>
beginAggregation(BufferAllocator allocator, HttpMessage start)

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

Creates a new aggregated message from the specified start message.
public void
channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause)

Overrides default io.netty5.channel.ChannelHandler.channelExceptionCaught.

Gets called if a Throwable was thrown when handling inbound events.
protected boolean
private static FullHttpResponse
continueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline)

protected void
finishAggregation(BufferAllocator allocator, FullHttpMessage<?> aggregated)

Overrides io.netty5.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, Object
the accumulated message up to this point.
oversized
)

Overrides io.netty5.handler.codec.MessageAggregator.handleOversizedMessage.

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

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

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

Implements abstract io.netty5.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.netty5.handler.codec.MessageAggregator.isContentLengthInvalid.

Determine if the message start's content length is known, and if it greater than maxContentLength.
protected boolean
isLastContentMessage(HttpContent<C> msg)

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

Returns true if and only if the specified message is the last content message.
protected int
lengthForAggregation(FullHttpMessage<?>
to calculate length.
msg
)

Implements abstract io.netty5.handler.codec.MessageAggregator.lengthForAggregation.

Returns the length in bytes of the passed message.
protected int
lengthForContent(HttpContent<C>
to calculate length.
msg
)

Implements abstract io.netty5.handler.codec.MessageAggregator.lengthForContent.

Returns the length in bytes of the passed message.
protected Object
newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline)

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

Returns the 'continue response' for the specified start message if necessary.
private static FullHttpResponse
newErrorResponse(HttpResponseStatus status, BufferAllocator allocator, boolean emptyContent, boolean closeConnection)

protected HttpContent<C>
tryContentMessage(Object msg)

Implements abstract io.netty5.handler.codec.MessageAggregator.tryContentMessage.

If the passed msg is a content message then cast and return the same, else return null.
protected HttpMessage
tryStartMessage(Object msg)

Implements abstract io.netty5.handler.codec.MessageAggregator.tryStartMessage.

If the passed msg is a start message then cast and return the same, else return null.
Inherited from io.netty5.handler.codec.MessageAggregator:
acceptInboundMessagechannelInactivechannelReadCompletectxdecodehandlerAddedhandlerRemovedmaxContentLength