@Override
public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise)
throws Exception {
if (msg instanceof Frame) {
final Frame frame = (Frame) msg;
if (headerSent.compareAndSet(false, true)) {
final HttpResponse response = createResponse(Transports.CONTENT_TYPE_JAVASCRIPT);
ctx.writeAndFlush(response);
final ByteBuf content = wrapWithLN(new PreludeFrame().content());
final DefaultHttpContent preludeChunk = new DefaultHttpContent(content);
ctx.writeAndFlush(preludeChunk);
}
ctx.writeAndFlush(new DefaultHttpContent(wrapWithLN(frame.content())), promise);
if (frame instanceof CloseFrame) {
ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT).addListener(ChannelFutureListener.CLOSE);
}
if (maxBytesLimit(frame.content().readableBytes())) {
logger.debug("max bytesSize limit reached [{}]", config.maxStreamingBytesSize());
ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT).addListener(ChannelFutureListener.CLOSE);
}
} else {
ctx.writeAndFlush(ReferenceCountUtil.retain(msg), promise);