if (response instanceof XContentRestResponse) {
// if its a builder based response, and it was created with a CachedStreamOutput, we can release it
// after we write the response, and no need to do an extra copy because its not thread safe
XContentBuilder builder = ((XContentRestResponse) response).builder();
if (builder.payload() instanceof CachedStreamOutput.Entry) {
releaseContentListener = new NettyTransport.CacheFutureListener((CachedStreamOutput.Entry) builder.payload());
ChannelBuffer buf = ChannelBuffers.wrappedBuffer(builder.unsafeBytes(), 0, builder.unsafeBytesLength());
writeBuffer = ChannelBuffers.wrappedBuffer(writeBuffer, buf);
} else if (response.contentThreadSafe()) {
ChannelBuffer buf = ChannelBuffers.wrappedBuffer(builder.unsafeBytes(), 0, builder.unsafeBytesLength());
writeBuffer = ChannelBuffers.wrappedBuffer(writeBuffer, buf);