From 1f8a48a74f5a1f1d72ffec222c7a35f97d574e53 Mon Sep 17 00:00:00 2001 From: Violeta Georgieva Date: Wed, 7 Aug 2024 13:26:01 +0300 Subject: [PATCH] Reduce duplication (#3386) --- .../netty/http/server/HttpTrafficHandler.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) 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 15ff0222ef..bb40da2e9b 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 @@ -222,9 +222,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) { } } - DecoderResult decoderResult = request.decoderResult(); - if (decoderResult.isFailure()) { - sendDecodingFailures(decoderResult.cause(), msg); + if (handleDecodingFailures(request.decoderResult(), msg)) { return; } @@ -270,13 +268,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)) { + return; + } + ctx.fireChannelRead(msg); + } else if (msg instanceof LastHttpContent) { - DecoderResult decoderResult = ((LastHttpContent) msg).decoderResult(); - if (decoderResult.isFailure()) { - sendDecodingFailures(decoderResult.cause(), msg); + if (handleDecodingFailures(((LastHttpContent) msg).decoderResult(), msg)) { return; } - ctx.fireChannelRead(msg); } else { @@ -302,12 +303,9 @@ else if (overflow) { return; } - if (msg instanceof DecoderResultProvider) { - DecoderResult decoderResult = ((DecoderResultProvider) msg).decoderResult(); - if (decoderResult.isFailure()) { - sendDecodingFailures(decoderResult.cause(), msg); - return; - } + if (msg instanceof DecoderResultProvider && + handleDecodingFailures(((DecoderResultProvider) msg).decoderResult(), msg)) { + return; } ctx.fireChannelRead(msg); @@ -345,6 +343,14 @@ public void flush(ChannelHandlerContext ctx) { } } + boolean handleDecodingFailures(DecoderResult decoderResult, Object msg) { + if (decoderResult.isFailure()) { + sendDecodingFailures(decoderResult.cause(), msg); + return true; + } + return false; + } + void sendDecodingFailures(Throwable t, Object msg) { sendDecodingFailures(t, msg, null, null); }