From 6536d9ae60722b8a3d114fb5eb29a1a211ac3ce0 Mon Sep 17 00:00:00 2001 From: Johan Haleby Date: Sun, 19 Jul 2015 15:04:43 +0200 Subject: [PATCH 1/2] SSE now works with preceding channel handlers such as SSL --- .../io/reactivex/netty/protocol/http/sse/SSEInboundHandler.java | 2 +- .../io/reactivex/netty/protocol/http/sse/SseChannelHandler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SSEInboundHandler.java b/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SSEInboundHandler.java index b8326c3e..ab7545f6 100644 --- a/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SSEInboundHandler.java +++ b/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SSEInboundHandler.java @@ -75,7 +75,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) ChannelPipeline pipeline = ctx.channel().pipeline(); if (!HttpHeaders.isTransferEncodingChunked((HttpResponse) msg)) { - pipeline.addFirst(SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder()); + pipeline.addBefore(NAME, SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder()); /* * If there are buffered messages in the previous handler at the time this message is read, we would * not be able to convert the content into an SseEvent. For this reason, we also add the decoder after diff --git a/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SseChannelHandler.java b/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SseChannelHandler.java index 30e8058f..17bd0cdb 100644 --- a/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SseChannelHandler.java +++ b/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SseChannelHandler.java @@ -70,7 +70,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) ChannelPipeline pipeline = ctx.channel().pipeline(); if (!HttpHeaders.isTransferEncodingChunked((HttpResponse) msg)) { - pipeline.addFirst(SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder()); + pipeline.addBefore(NAME, SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder()); /* * If there are buffered messages in the previous handler at the time this message is read, we would * not be able to convert the content into an SseEvent. For this reason, we also add the decoder after From 52b44a81be15a6035a12b5289ce2545d39d6ccd2 Mon Sep 17 00:00:00 2001 From: Johan Haleby Date: Thu, 23 Jul 2015 09:26:28 +0200 Subject: [PATCH 2/2] Removed chunked encdding if-statement since it's not needed --- .../netty/protocol/http/sse/SSEInboundHandler.java | 13 +------------ .../netty/protocol/http/sse/SseChannelHandler.java | 13 +------------ 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SSEInboundHandler.java b/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SSEInboundHandler.java index ab7545f6..b2be2454 100644 --- a/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SSEInboundHandler.java +++ b/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SSEInboundHandler.java @@ -74,18 +74,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) ctx.channel().attr(ClientRequestResponseConverter.DISCARD_CONNECTION).set(true); // SSE traffic should always discard connection on close. ChannelPipeline pipeline = ctx.channel().pipeline(); - if (!HttpHeaders.isTransferEncodingChunked((HttpResponse) msg)) { - pipeline.addBefore(NAME, SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder()); - /* - * If there are buffered messages in the previous handler at the time this message is read, we would - * not be able to convert the content into an SseEvent. For this reason, we also add the decoder after - * this handler, so that we can handle the buffered messages. - * See the class level javadoc for more details. - */ - pipeline.addAfter(NAME, SSE_DECODER_POST_INBOUND_HANDLER, new ServerSentEventDecoder()); - } else { - pipeline.addAfter(NAME, SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder()); - } + pipeline.addAfter(NAME, SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder()); ctx.fireChannelRead(msg); } else if (msg instanceof LastHttpContent) { LastHttpContent lastHttpContent = (LastHttpContent) msg; diff --git a/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SseChannelHandler.java b/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SseChannelHandler.java index 17bd0cdb..563a4ce1 100644 --- a/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SseChannelHandler.java +++ b/rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/SseChannelHandler.java @@ -69,18 +69,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) ctx.channel().attr(ClientRequestResponseConverter.DISCARD_CONNECTION).set(true); // SSE traffic should always discard connection on close. ChannelPipeline pipeline = ctx.channel().pipeline(); - if (!HttpHeaders.isTransferEncodingChunked((HttpResponse) msg)) { - pipeline.addBefore(NAME, SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder()); - /* - * If there are buffered messages in the previous handler at the time this message is read, we would - * not be able to convert the content into an SseEvent. For this reason, we also add the decoder after - * this handler, so that we can handle the buffered messages. - * See the class level javadoc for more details. - */ - pipeline.addAfter(NAME, SSE_DECODER_POST_INBOUND_HANDLER, new ServerSentEventDecoder()); - } else { - pipeline.addAfter(NAME, SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder()); - } + pipeline.addAfter(NAME, SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder()); ctx.fireChannelRead(msg); } else if (msg instanceof LastHttpContent) { LastHttpContent lastHttpContent = (LastHttpContent) msg;