From 622cc232f0647b7e6c9581ed7417436e14f15d9b Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 26 Sep 2019 22:11:41 +0200 Subject: [PATCH] Use configured ByteBufAllocator in InboundHttp2ToHttpAdapter (#9611) Motivation: At the moment we use Unpooled.buffer(...) in InboundHttp2ToHttpAdapter when we need to do a copy of the message. We should better use the configured ByteBufAllocator for the Channel Modifications: Change internal interface to also take the ByteBufAllocator as argument and use it when we need to allocate a ByteBuf. Result: Use the "correct" ByteBufAllocator in InboundHttp2ToHttpAdapter in all cases --- .../handler/codec/http2/InboundHttp2ToHttpAdapter.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java index 73f56064fd..5284dfff3a 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java @@ -16,7 +16,6 @@ package io.netty.handler.codec.http2; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; -import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.FullHttpMessage; import io.netty.handler.codec.http.FullHttpRequest; @@ -53,9 +52,9 @@ public class InboundHttp2ToHttpAdapter extends Http2EventAdapter { } @Override - public FullHttpMessage copyIfNeeded(FullHttpMessage msg) { + public FullHttpMessage copyIfNeeded(ByteBufAllocator allocator, FullHttpMessage msg) { if (msg instanceof FullHttpRequest) { - FullHttpRequest copy = ((FullHttpRequest) msg).replace(Unpooled.buffer(0)); + FullHttpRequest copy = ((FullHttpRequest) msg).replace(allocator.buffer(0)); copy.headers().remove(HttpHeaderNames.EXPECT); return copy; } @@ -200,7 +199,7 @@ public class InboundHttp2ToHttpAdapter extends Http2EventAdapter { if (sendDetector.mustSendImmediately(msg)) { // Copy the message (if necessary) before sending. The content is not expected to be copied (or used) in // this operation but just in case it is used do the copy before sending and the resource may be released - final FullHttpMessage copy = endOfStream ? null : sendDetector.copyIfNeeded(msg); + final FullHttpMessage copy = endOfStream ? null : sendDetector.copyIfNeeded(ctx.alloc(), msg); fireChannelRead(ctx, msg, release, stream); return copy; } @@ -354,9 +353,10 @@ public class InboundHttp2ToHttpAdapter extends Http2EventAdapter { * with a 'Expect: 100-continue' header. The message will be sent immediately, * and the data will be queued and sent at the end of the stream. * + * @param allocator The {@link ByteBufAllocator} that can be used to allocate * @param msg The message which has just been sent due to {@link #mustSendImmediately(FullHttpMessage)} * @return A modified copy of the {@code msg} or {@code null} if a copy is not needed. */ - FullHttpMessage copyIfNeeded(FullHttpMessage msg); + FullHttpMessage copyIfNeeded(ByteBufAllocator allocator, FullHttpMessage msg); } }