Package io.netty.handler.codec.http
Class HttpObjectAggregator
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.MessageToMessageDecoder<I>
-
- io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
-
- io.netty.handler.codec.http.HttpObjectAggregator
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler
- Direct Known Subclasses:
HttpClientUpgradeHandler,HttpServerUpgradeHandler
public class HttpObjectAggregator extends io.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
AChannelHandlerthat aggregates anHttpMessageand its followingHttpContents into a singleFullHttpRequestorFullHttpResponse(depending on if it used to handle requests or responses) with no followingHttpContents. It is useful when you don't want to take care of HTTP messages whose transfer encoding is 'chunked'. Insert this handler afterHttpResponseDecoderin theChannelPipelineif being used to handle responses, or afterHttpRequestDecoderandHttpResponseEncoderin theChannelPipelineif 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
Be aware thatHttpServerCodecbefore theHttpObjectAggregatoras it functions as both aHttpRequestDecoderand aHttpResponseEncoder.HttpObjectAggregatormay end up sending aHttpResponse: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 Summary
Constructors Constructor Description HttpObjectAggregator(int maxContentLength)Creates a new instance.HttpObjectAggregator(int maxContentLength, boolean closeOnExpectationFailed)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaggregate(FullHttpMessage aggregated, HttpContent content)protected FullHttpMessagebeginAggregation(HttpMessage start, io.netty.buffer.ByteBuf content)protected booleancloseAfterContinueResponse(Object msg)protected voidfinishAggregation(FullHttpMessage aggregated)protected voidhandleOversizedMessage(io.netty.channel.ChannelHandlerContext ctx, HttpMessage oversized)protected booleanignoreContentAfterContinueResponse(Object msg)protected booleanisAggregated(HttpObject msg)protected booleanisContentLengthInvalid(HttpMessage start, int maxContentLength)protected booleanisContentMessage(HttpObject msg)protected booleanisLastContentMessage(HttpContent msg)protected booleanisStartMessage(HttpObject msg)protected ObjectnewContinueResponse(HttpMessage start, int maxContentLength, io.netty.channel.ChannelPipeline pipeline)-
Methods inherited from class io.netty.handler.codec.MessageAggregator
acceptInboundMessage, channelInactive, channelReadComplete, ctx, decode, handlerAdded, handlerRemoved, isHandlingOversizedMessage, maxContentLength, maxCumulationBufferComponents, releaseCurrentMessage, setMaxCumulationBufferComponents
-
-
-
-
Constructor Detail
-
HttpObjectAggregator
public HttpObjectAggregator(int maxContentLength)
Creates a new instance.- Parameters:
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.
-
HttpObjectAggregator
public HttpObjectAggregator(int maxContentLength, boolean closeOnExpectationFailed)Creates a new instance.- Parameters:
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 thentruemeans close the connection. otherwise the connection will remain open and data will be consumed and discarded until the next request is received.
-
-
Method Detail
-
isStartMessage
protected boolean isStartMessage(HttpObject msg) throws Exception
- Specified by:
isStartMessagein classio.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>- Throws:
Exception
-
isContentMessage
protected boolean isContentMessage(HttpObject msg) throws Exception
- Specified by:
isContentMessagein classio.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>- Throws:
Exception
-
isLastContentMessage
protected boolean isLastContentMessage(HttpContent msg) throws Exception
- Specified by:
isLastContentMessagein classio.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>- Throws:
Exception
-
isAggregated
protected boolean isAggregated(HttpObject msg) throws Exception
- Specified by:
isAggregatedin classio.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>- Throws:
Exception
-
isContentLengthInvalid
protected boolean isContentLengthInvalid(HttpMessage start, int maxContentLength)
- Specified by:
isContentLengthInvalidin classio.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
-
newContinueResponse
protected Object newContinueResponse(HttpMessage start, int maxContentLength, io.netty.channel.ChannelPipeline pipeline)
- Specified by:
newContinueResponsein classio.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
-
closeAfterContinueResponse
protected boolean closeAfterContinueResponse(Object msg)
- Specified by:
closeAfterContinueResponsein classio.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
-
ignoreContentAfterContinueResponse
protected boolean ignoreContentAfterContinueResponse(Object msg)
- Specified by:
ignoreContentAfterContinueResponsein classio.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
-
beginAggregation
protected FullHttpMessage beginAggregation(HttpMessage start, io.netty.buffer.ByteBuf content) throws Exception
- Specified by:
beginAggregationin classio.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>- Throws:
Exception
-
aggregate
protected void aggregate(FullHttpMessage aggregated, HttpContent content) throws Exception
- Overrides:
aggregatein classio.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>- Throws:
Exception
-
finishAggregation
protected void finishAggregation(FullHttpMessage aggregated) throws Exception
- Overrides:
finishAggregationin classio.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>- Throws:
Exception
-
handleOversizedMessage
protected void handleOversizedMessage(io.netty.channel.ChannelHandlerContext ctx, HttpMessage oversized) throws Exception- Overrides:
handleOversizedMessagein classio.netty.handler.codec.MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>- Throws:
Exception
-
-