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());
}
});
}
Aggregations