Skip to content

Commit

Permalink
Ensure Http2FrameCodec is created only when there is a need for proto…
Browse files Browse the repository at this point in the history
…col upgrade
  • Loading branch information
violetagg committed Sep 23, 2022
1 parent ed16dc5 commit 275238f
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,10 @@ static final class H2CleartextCodec extends ChannelHandlerAdapter {
public void handlerAdded(ChannelHandlerContext ctx) {
ChannelPipeline pipeline = ctx.pipeline();
if (addHttp2FrameCodec) {
pipeline.addAfter(ctx.name(), NettyPipeline.HttpCodec, upgrader.http2FrameCodec);
pipeline.addAfter(ctx.name(), NettyPipeline.HttpCodec, upgrader.http2FrameCodecBuilder.build());
}

pipeline.addAfter(ctx.pipeline().context(upgrader.http2FrameCodec).name(),
pipeline.addAfter(ctx.pipeline().context(Http2FrameCodec.class).name(),
NettyPipeline.H2MultiplexHandler, new Http2MultiplexHandler(upgrader));

pipeline.remove(this);
Expand Down Expand Up @@ -849,7 +849,7 @@ static final class Http11OrH2CleartextCodec extends ChannelInitializer<Channel>
final BiPredicate<HttpServerRequest, HttpServerResponse> compressPredicate;
final HttpServerFormDecoderProvider formDecoderProvider;
final BiFunction<ConnectionInfo, HttpRequest, ConnectionInfo> forwardedHeaderHandler;
final Http2FrameCodec http2FrameCodec;
final Http2FrameCodecBuilder http2FrameCodecBuilder;
final ConnectionObserver listener;
final BiFunction<? super Mono<Void>, ? super Connection, ? extends Mono<Void>>
mapHandle;
Expand Down Expand Up @@ -878,7 +878,7 @@ static final class Http11OrH2CleartextCodec extends ChannelInitializer<Channel>
this.compressPredicate = compressPredicate;
this.formDecoderProvider = formDecoderProvider;
this.forwardedHeaderHandler = forwardedHeaderHandler;
Http2FrameCodecBuilder http2FrameCodecBuilder =
this.http2FrameCodecBuilder =
Http2FrameCodecBuilder.forServer()
.validateHeaders(validate)
.initialSettings(http2Settings);
Expand All @@ -888,7 +888,6 @@ static final class Http11OrH2CleartextCodec extends ChannelInitializer<Channel>
LogLevel.DEBUG,
"reactor.netty5.http.server.h2"));
}
this.http2FrameCodec = http2FrameCodecBuilder.build();
this.listener = listener;
this.mapHandle = mapHandle;
this.metricsRecorder = metricsRecorder;
Expand All @@ -912,7 +911,7 @@ protected void initChannel(Channel ch) {
@Nullable
public HttpServerUpgradeHandler.UpgradeCodec newUpgradeCodec(CharSequence protocol) {
if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
return new Http2ServerUpgradeCodec(http2FrameCodec, new H2CleartextCodec(this, false, false));
return new Http2ServerUpgradeCodec(http2FrameCodecBuilder.build(), new H2CleartextCodec(this, false, false));
}
else {
return null;
Expand Down

0 comments on commit 275238f

Please sign in to comment.