Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce duplication #3386

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down