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
This commit is contained in:
Norman Maurer 2019-09-26 22:11:41 +02:00 committed by GitHub
parent 1f4b9e36ea
commit 622cc232f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}
}