diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/server/HttpTrafficHandler.java b/reactor-netty-http/src/main/java/reactor/netty/http/server/HttpTrafficHandler.java index d22d119a1b..a52dfb6270 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/server/HttpTrafficHandler.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/server/HttpTrafficHandler.java @@ -225,9 +225,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) { } } - DecoderResult decoderResult = request.decoderResult(); - if (decoderResult.isFailure()) { - sendDecodingFailures(decoderResult.cause(), msg, validateHeaders); + if (handleDecodingFailures(request.decoderResult(), msg, validateHeaders)) { return; } @@ -275,13 +273,16 @@ else if (persistentConnection && pendingResponses == 0) { if (msg == EMPTY_LAST_CONTENT) { ctx.fireChannelRead(msg); } + else if (msg.getClass() == DefaultLastHttpContent.class) { + if (handleDecodingFailures(((DefaultLastHttpContent) msg).decoderResult(), msg, validateHeaders)) { + return; + } + ctx.fireChannelRead(msg); + } else if (msg instanceof LastHttpContent) { - DecoderResult decoderResult = ((LastHttpContent) msg).decoderResult(); - if (decoderResult.isFailure()) { - sendDecodingFailures(decoderResult.cause(), msg, validateHeaders); + if (handleDecodingFailures(((LastHttpContent) msg).decoderResult(), msg, validateHeaders)) { return; } - ctx.fireChannelRead(msg); } else { @@ -307,12 +308,9 @@ else if (overflow) { return; } - if (msg instanceof DecoderResultProvider) { - DecoderResult decoderResult = ((DecoderResultProvider) msg).decoderResult(); - if (decoderResult.isFailure()) { - sendDecodingFailures(decoderResult.cause(), msg, validateHeaders); - return; - } + if (msg instanceof DecoderResultProvider && + handleDecodingFailures(((DecoderResultProvider) msg).decoderResult(), msg, validateHeaders)) { + return; } ctx.fireChannelRead(msg); @@ -350,6 +348,14 @@ public void flush(ChannelHandlerContext ctx) { } } + boolean handleDecodingFailures(DecoderResult decoderResult, Object msg, boolean validateHeaders) { + if (decoderResult.isFailure()) { + sendDecodingFailures(decoderResult.cause(), msg, validateHeaders); + return true; + } + return false; + } + void sendDecodingFailures(Throwable t, Object msg, boolean validateHeaders) { sendDecodingFailures(t, msg, null, null, validateHeaders); }