public class HttpObjectAggregator extends io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
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.
ChannelPipelinep = ...; ... p.addLast("decoder", newHttpRequestDecoder()); p.addLast("encoder", newHttpResponseEncoder()); p.addLast("aggregator", newHttpObjectAggregator(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.
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 |
| Constructor and Description |
|---|
HttpObjectAggregator(int maxContentLength)
Creates a new instance.
|
HttpObjectAggregator(int maxContentLength,
boolean closeOnExpectationFailed)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
aggregate(FullHttpMessage aggregated,
HttpContent content) |
protected FullHttpMessage |
beginAggregation(HttpMessage start,
io.netty.buffer.ByteBuf content) |
protected boolean |
closeAfterContinueResponse(Object msg) |
protected void |
finishAggregation(FullHttpMessage aggregated) |
protected void |
handleOversizedMessage(io.netty.channel.ChannelHandlerContext ctx,
HttpMessage oversized) |
protected boolean |
ignoreContentAfterContinueResponse(Object msg) |
protected boolean |
isAggregated(HttpObject msg) |
protected boolean |
isContentLengthInvalid(HttpMessage start,
int maxContentLength) |
protected boolean |
isContentMessage(HttpObject msg) |
protected boolean |
isLastContentMessage(HttpContent msg) |
protected boolean |
isStartMessage(HttpObject msg) |
protected Object |
newContinueResponse(HttpMessage start,
int maxContentLength,
io.netty.channel.ChannelPipeline pipeline) |
acceptInboundMessage, channelInactive, channelReadComplete, ctx, decode, handlerAdded, handlerRemoved, isHandlingOversizedMessage, maxContentLength, maxCumulationBufferComponents, setMaxCumulationBufferComponentspublic HttpObjectAggregator(int maxContentLength)
maxContentLength - 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.public HttpObjectAggregator(int maxContentLength,
boolean closeOnExpectationFailed)
maxContentLength - 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.closeOnExpectationFailed - 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.protected boolean isStartMessage(HttpObject msg) throws Exception
isStartMessage in class io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected boolean isContentMessage(HttpObject msg) throws Exception
isContentMessage in class io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected boolean isLastContentMessage(HttpContent msg) throws Exception
isLastContentMessage in class io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected boolean isAggregated(HttpObject msg) throws Exception
isAggregated in class io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected boolean isContentLengthInvalid(HttpMessage start, int maxContentLength)
isContentLengthInvalid in class io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>protected Object newContinueResponse(HttpMessage start, int maxContentLength, io.netty.channel.ChannelPipeline pipeline)
newContinueResponse in class io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>protected boolean closeAfterContinueResponse(Object msg)
closeAfterContinueResponse in class io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>protected boolean ignoreContentAfterContinueResponse(Object msg)
ignoreContentAfterContinueResponse in class io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>protected FullHttpMessage beginAggregation(HttpMessage start, io.netty.buffer.ByteBuf content) throws Exception
beginAggregation in class io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected void aggregate(FullHttpMessage aggregated, HttpContent content) throws Exception
aggregate in class io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected void finishAggregation(FullHttpMessage aggregated) throws Exception
finishAggregation in class io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected void handleOversizedMessage(io.netty.channel.ChannelHandlerContext ctx,
HttpMessage oversized)
throws Exception
handleOversizedMessage in class io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>ExceptionCopyright © 2008–2024 The Netty Project. All rights reserved.