Skip to content

Commit

Permalink
Use configured ByteBufAllocator in InboundHttp2ToHttpAdapter (#9611)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
normanmaurer committed Sep 26, 2019
1 parent 8f23e27 commit 43f7a9e
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

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;
Expand Down Expand Up @@ -53,9 +52,9 @@ public boolean mustSendImmediately(FullHttpMessage msg) {
}

@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;
}
Expand Down Expand Up @@ -200,7 +199,7 @@ protected FullHttpMessage processHeadersBegin(ChannelHandlerContext ctx, Http2St
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;
}
Expand Down Expand Up @@ -354,9 +353,10 @@ private interface ImmediateSendDetector {
* 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);
}
}

0 comments on commit 43f7a9e

Please sign in to comment.