11/*
2- * Copyright (c) 2020-2021 VMware, Inc. or its affiliates, All Rights Reserved.
2+ * Copyright (c) 2020-2023 VMware, Inc. or its affiliates, All Rights Reserved.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3535 * {@link ChannelInboundHandlerAdapter} prior {@link reactor.netty.channel.ChannelOperationsHandler}
3636 * for handling H2/H2C use cases. HTTP/1.x use cases are delegated to
3737 * {@link reactor.netty.channel.ChannelOperationsHandler} without any interference.
38+ * <p>
39+ * Once the channel is activated, the upgrade is decided (H2C or HTTP/1.1) and in case H2/H2C the first SETTINGS frame
40+ * is received, this handler is not needed any more. Thus said {@link #channelInactive(ChannelHandlerContext)}
41+ * is invoked only in case there are issues with the connection itself.
3842 *
3943 * @author Violeta Georgieva
4044 * @since 1.0.0
@@ -79,6 +83,11 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
7983 ctx .fireChannelRead (msg );
8084 }
8185
86+ @ Override
87+ public void channelInactive (ChannelHandlerContext ctx ) {
88+ ctx .fireExceptionCaught (new PrematureCloseException ("Connection prematurely closed BEFORE response" ));
89+ }
90+
8291 @ Override
8392 public void userEventTriggered (ChannelHandlerContext ctx , Object evt ) {
8493 Channel channel = ctx .channel ();
@@ -99,6 +108,7 @@ else if (evt == UPGRADE_REJECTED) {
99108 log .debug (format (channel , "The upgrade to H2C protocol was rejected, continue using HTTP/1.x protocol." ));
100109 }
101110 sendNewState (Connection .from (channel ), HttpClientState .UPGRADE_REJECTED );
111+ ctx .pipeline ().remove (this );
102112 }
103113 ctx .fireUserEventTriggered (evt );
104114 }
0 commit comments