Search in sources :

Example 1 with ByteBufRef

use of ratpack.bytebuf.ByteBufRef in project ratpack by ratpack.

the class ContentAggregatingRequestAction method addResponseHandlers.

@Override
protected void addResponseHandlers(ChannelPipeline p, Downstream<? super ReceivedResponse> downstream) {
    p.addLast(AGGREGATOR_HANDLER_NAME, new NoContentLengthOnNoBodyHttpObjectAggregator(requestConfig.maxContentLength));
    p.addLast(RESPONSE_HANDLER_NAME, new SimpleChannelInboundHandler<FullHttpResponse>(false) {

        @Override
        protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse response) throws Exception {
            response.touch();
            dispose(ctx.pipeline(), response);
            ByteBuf content = new ByteBufRef(response.content());
            execution.onComplete(() -> {
                if (content.refCnt() > 0) {
                    content.release();
                }
            });
            success(downstream, toReceivedResponse(response, content));
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            cause = decorateException(cause);
            error(downstream, cause);
            forceDispose(ctx.pipeline());
        }
    });
}
Also used : FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) ByteBufRef(ratpack.bytebuf.ByteBufRef)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)1 ByteBufRef (ratpack.bytebuf.ByteBufRef)1