Skip to content

Commit

Permalink
fix http ERR_CONTENT_LENGTH_MISMATCH. #2916
Browse files Browse the repository at this point in the history
  • Loading branch information
hengyunabc committed Sep 25, 2024
1 parent 66d6712 commit 58237ce
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,15 @@ public static DefaultFullHttpResponse directView(File dir, String path, FullHttp
} finally {
IOUtils.close(fileInputStream);
}
ctx.write(fullResp);
ChannelFuture future = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
future.addListener(ChannelFutureListener.CLOSE);
ChannelFuture channelFuture = ctx.writeAndFlush(fullResp);
channelFuture.addListener((ChannelFutureListener) future -> {
if (future.isSuccess()) {
ChannelFuture lastContentFuture = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
lastContentFuture.addListener(ChannelFutureListener.CLOSE);
} else {
future.channel().close();
}
});
return fullResp;
}
logger.info("file {} size bigger than {}, send by future.",file.getName(), MIN_NETTY_DIRECT_SEND_SIZE);
Expand Down

0 comments on commit 58237ce

Please sign in to comment.