Skip to content

Commit

Permalink
Do not close the empty full message when invoking SimpleCompressionHa…
Browse files Browse the repository at this point in the history
…ndler out of the pipeline
  • Loading branch information
violetagg committed Sep 21, 2022
1 parent 95daf6e commit 384d01c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ else if (channel().pipeline()
.get(NettyPipeline.CompressionHandler) == null) {
SimpleCompressionHandler handler = new SimpleCompressionHandler();
try {
// decodeAndClose(...) is needed only to initialize the acceptEncodingQueue
handler.decodeAndClose(channel().pipeline().context(NettyPipeline.ReactiveBridge), nettyRequest);
// decode(...) is needed only to initialize the acceptEncodingQueue
handler.decode(channel().pipeline().context(NettyPipeline.ReactiveBridge), nettyRequest, false);

addHandlerFirst(NettyPipeline.CompressionHandler, handler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public Future<Void> write(ChannelHandlerContext ctx, Object msg) {
return super.write(ctx, msg);
}

@Override
protected void decodeAndClose(ChannelHandlerContext ctx, HttpRequest msg) throws Exception {
void decode(ChannelHandlerContext ctx, HttpRequest msg, boolean release) throws Exception {
HttpRequest request = msg;
if (msg instanceof FullHttpRequest fullHttpRequest &&
(!fullHttpRequest.isAccessible() || fullHttpRequest.payload().readableBytes() == 0)) {
Expand All @@ -48,7 +47,15 @@ protected void decodeAndClose(ChannelHandlerContext ctx, HttpRequest msg) throws
// 2. fireChannelRead(...) is invoked at the end of super.decodeAndClose(...) which will end up
// in io.netty5.channel.DefaultChannelPipeline.onUnhandledInboundMessage which closes the msg.
request = new DefaultHttpRequest(msg.protocolVersion(), msg.method(), msg.uri(), msg.headers());
if (release && fullHttpRequest.isAccessible()) {
fullHttpRequest.close();
}
}
super.decodeAndClose(ctx, request);
}

@Override
protected void decodeAndClose(ChannelHandlerContext ctx, HttpRequest msg) throws Exception {
decode(ctx, msg, true);
}
}

0 comments on commit 384d01c

Please sign in to comment.