pipeline.addLast(SSE_ENCODER_HANDLER_NAME, SERVER_SENT_EVENT_ENCODER);
pipeline.addLast(SSE_RESPONSE_HEADERS_COMPLETER, new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (HttpServerResponse.class.isAssignableFrom(msg.getClass())) {
@SuppressWarnings("rawtypes")
HttpServerResponse rxResponse = (HttpServerResponse) msg;
String contentTypeHeader = rxResponse.getHeaders().get(CONTENT_TYPE);
if (null == contentTypeHeader) {
rxResponse.getHeaders().set(CONTENT_TYPE, "text/event-stream");
}
}
super.write(ctx, msg, promise);
}
});