From 8796fd30250da86c9b0cefa7ccb1d05743f7a3b4 Mon Sep 17 00:00:00 2001 From: Derek Troy-West Date: Thu, 16 Apr 2015 21:45:32 +1000 Subject: [PATCH] Change AggregatedFullHttpMessage to contain a content ByteBuf Motivation: Other implementations of FullHttpMessage allow .toString to be called after the Message has been released This brings AggregatedFullHttpMessage into line with those impls. Modifications: - Changed AggregatedFullHttpMessage to no longer be a sub-class of DefaultByteBufHolder - Changes AggregatedFullHttpMessage to implement ByteBufHolder - Hold the content buffer internally to AggregatedFullHttpMessage - Implement the required content() and release() methods that were missing - Do not check refcnt when accessing content() (similar to DefaultFullHttpMessage) Result: A released AggregatedFullHttpMessage can have .toString called without throwing an exception --- .../codec/http/HttpObjectAggregator.java | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java index f3c726d72c..5a68403c25 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java @@ -16,7 +16,7 @@ package io.netty.handler.codec.http; import io.netty.buffer.ByteBuf; -import io.netty.buffer.DefaultByteBufHolder; +import io.netty.buffer.ByteBufHolder; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; @@ -188,13 +188,14 @@ public class HttpObjectAggregator } } - private abstract static class AggregatedFullHttpMessage extends DefaultByteBufHolder implements FullHttpMessage { + private abstract static class AggregatedFullHttpMessage implements ByteBufHolder, FullHttpMessage { protected final HttpMessage message; + private final ByteBuf content; private HttpHeaders trailingHeaders; AggregatedFullHttpMessage(HttpMessage message, ByteBuf content, HttpHeaders trailingHeaders) { - super(content); this.message = message; + this.content = content; this.trailingHeaders = trailingHeaders; } @@ -239,29 +240,49 @@ public class HttpObjectAggregator } @Override - public FullHttpMessage retain(int increment) { - super.retain(increment); - return this; + public ByteBuf content() { + return content; + } + + @Override + public int refCnt() { + return content.refCnt(); } @Override public FullHttpMessage retain() { - super.retain(); + content.retain(); + return this; + } + + @Override + public FullHttpMessage retain(int increment) { + content.retain(increment); return this; } @Override public FullHttpMessage touch(Object hint) { - super.touch(hint); + content.touch(hint); return this; } @Override public FullHttpMessage touch() { - super.touch(); + content.touch(); return this; } + @Override + public boolean release() { + return content.release(); + } + + @Override + public boolean release(int decrement) { + return content.release(decrement); + } + @Override public abstract FullHttpMessage copy();