} else {
pipeline.addAfter(NAME, SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder());
}
ctx.fireChannelRead(msg);
} else if (msg instanceof LastHttpContent) {
LastHttpContent lastHttpContent = (LastHttpContent) msg;
/**
* The entire pipeline is set based on the assumption that LastHttpContent signals the end of the stream.
* Since, here we are only passing the content to the rest of the pipeline, it becomes imperative to
* also pass LastHttpContent as such.
* For this reason, we send the LastHttpContent again in the pipeline. For this event sent, the content
* buffer will already be read and hence will not be read again. This message serves as only containing
* the trailing headers.
* However, we need to increment the ref count of the content so that the assumptions down the line of the
* ByteBuf always being released by the last pipeline handler will not break (as ServerSentEventDecoder releases
* the ByteBuf after read).
*/
lastHttpContent.content().retain(); // pseudo retain so that the last handler of the pipeline can release it.
if (lastHttpContent.content().isReadable()) {
ctx.fireChannelRead(lastHttpContent.content());
}
ctx.fireChannelRead(msg); // Since the content is already consumed above (by the SSEDecoder), this is just
// as sending just trailing headers. This is critical to mark the end of stream.