GeezerVison is showing github.com — Visibility of Http3ConnectionHandler abstract methods · Issue #16992 · netty/netty
Visibility of Http3ConnectionHandler abstract methods #16992DescriptionHttp3ConnectionHandler is declared as a public abstract class, which suggests it is intended to be extended. However, its abstract template methods (initBidirectionalStream and initUnidirectionalStream) have package-private visibility, making it impossible for subclasses outside the http3 package to implement them.
Is it intentional that all subclasses of Http3ConnectionHandler are expected to reside within the http3 package? If so, the public visibility of Http3ConnectionHandler could be interpreted as somewhat misleading, since it cannot be meaningfully extended outside the package.
If external extension is intended, would it make sense to change the visibility of these abstract methods from package-private to protected? This would align the visibility of the required extension points with the class itself while preserving the existing API and behavior. Activityyawkat commented on Jun 25, 2026 Http3ConnectionHandler is not designed for external extension, but it still sometimes makes sense to use it directly instead of one of its subclasses, when writing code that can work with either subclass. Reacted by Santhosh Mohan sanjomo commented on Jun 25, 2026 ContributorAuthor More actions @yawkat Thanks for the clarification.
Our use case came up while implementing a WebTransport client handler. We couldn't use/extend Http3ClientConnectionHandler because it explicitly prohibits server-initiated bidirectional streams, which WebTransport requires. Our next thought was to extend the abstract Http3ConnectionHandler instead. However, since its abstract template methods are package-private, it isn't possible to implement them from outside the http3 package.
From our perspective, that leaves two possible approaches:
- Change the abstract template methods to
protected, allowing external subclasses to implement them.
- Place the
WebTransportClientConnectionHandler inside the http3 package, which would introduce an dependency on Netty's internal package structure and put additional maintenance pressure on downstream projects.
Is there another approach you would recommend for this use case? We'd be happy to follow the intended extension model if there's a better solution. normanmaurer commented on Jun 25, 2026 Can you point me to your code ? sanjomo commented on Jun 25, 2026 ContributorAuthor More actions
|
void initBidirectionalStream(ChannelHandlerContext ctx, QuicStreamChannel channel) { |
- This makes using Http3ClientConnectionHandler impossible since webtransport allow server initiated bi-directional streams
|
public void channelRead(ChannelHandlerContext ctx, Object msg) { |
. - channelRead branches logic to abstract methods which must be implemented in the implementation
If I declare in my external project like this
package io.github.webtransport4j.client; // **external project**
public final class WebTransportClientConnectionHandler extends Http3ConnectionHandler {
@Override //_Method does not override method from its superclass since it is package private_
void initBidirectionalStream(ChannelHandlerContext ctx, QuicStreamChannel channel) {
}
@Override //_Method does not override method from its superclass since it is package private_
void initUnidirectionalStream(ChannelHandlerContext ctx, QuicStreamChannel streamChannel) {
}
}
I do get this error : Class 'WebTransportClientConnectionHandler' must either be declared abstract or implement abstract method 'initBidirectionalStream(ChannelHandlerContext, QuicStreamChannel)' in 'Http3ConnectionHandler' sanjomo commented on Jun 26, 2026 ContributorAuthor More actions @normanmaurer Please guide us based on the above context.
During server development, we did not encounter this issue because the server only needs to handle the CONNECT request to establish the WebTransport session. After the session is established, we can successfully create server-initiated bidirectional streams using connectStreamChannel.parent().createStream(QuicStreamType.BIDIRECTIONAL, streamHandler) without any problems.
However, during client development, we were unable to use Http3ClientConnection because it rejects incoming server-initiated bidirectional streams. To support this behavior, we had to implement a separate client by extending Http3ConnectionHandler, which can handle server-initiated bidirectional streams too. Zhengcy05 commented on Jun 29, 2026 I have a question. I feel like this is a code bug. Do I understand that we shouldn't prioritize to change the abstract template methods to protected 🤔 Reacted by Santhosh Mohan sanjomo commented on Jun 29, 2026 ContributorAuthor More actions
I have a question. I feel like this is a code bug. Do I understand that we shouldn't prioritise to change the abstract template methods to protected 🤔
I think ,its not straightforward to change just those methods to protected , we should make constructors and other apis to protected as well, or move the implementation to http3 module since protocols like webtransport are an extension of http3 normanmaurer commented on Jun 30, 2026 sanjomo commented on Jun 30, 2026 ContributorAuthor More actions @normanmaurer yes, to be precise client supporting server initiated bi-directional stream instead of rejecting it like http3 normanmaurer commented on Jun 30, 2026 @sanjomo is this the only thing that needs to be supported or any other changes ? sanjomo commented on Jun 30, 2026 ContributorAuthor More actions @normanmaurer actually we need http3client as well, to process CONNECT request and Capsule handling, then we can use the raw quic connection created by the http3client to create uni and bidirectional streams for our webtransport streams, is there anyway to accomplish this with current client without any or limited modification?
this is the client sample provided with netty module
public final class Http3ClientExample {
private Http3ClientExample() { }
public static void main(String... args) throws Exception {
EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory());
try {
QuicSslContext context = QuicSslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.applicationProtocols(Http3.supportedApplicationProtocols()).build();
ChannelHandler codec = Http3.newQuicClientCodecBuilder()
.sslContext(context)
.maxIdleTimeout(5000, TimeUnit.MILLISECONDS)
.initialMaxData(10000000)
.initialMaxStreamDataBidirectionalLocal(1000000)
.build();
Bootstrap bs = new Bootstrap();
Channel channel = bs.group(group)
.channel(NioDatagramChannel.class)
.handler(codec)
.bind(0).sync().channel();
QuicChannel quicChannel = QuicChannel.newBootstrap(channel)
.handler(new Http3ClientConnectionHandler())
.remoteAddress(new InetSocketAddress(NetUtil.LOCALHOST4, Http3ServerExample.PORT))
.connect()
.get();
QuicStreamChannel streamChannel = Http3.newRequestStream(quicChannel,
new Http3RequestStreamInboundHandler() {
@Override
protected void channelRead(ChannelHandlerContext ctx, Http3HeadersFrame frame) {
ReferenceCountUtil.release(frame);
}
@Override
protected void channelRead(ChannelHandlerContext ctx, Http3DataFrame frame) {
System.err.print(frame.content().toString(CharsetUtil.US_ASCII));
ReferenceCountUtil.release(frame);
}
@Override
protected void channelInputClosed(ChannelHandlerContext ctx) {
ctx.close();
}
}).sync().getNow();
// Write the Header frame and send the FIN to mark the end of the request.
// After this it's not possible anymore to write any more data.
Http3HeadersFrame frame = new DefaultHttp3HeadersFrame();
frame.headers().method("GET").path("/")
.authority(NetUtil.LOCALHOST4.getHostAddress() + ":" + Http3ServerExample.PORT)
.scheme("https");
streamChannel.writeAndFlush(frame)
.addListener(QuicStreamChannel.SHUTDOWN_OUTPUT).sync();
// Wait for the stream channel and quic channel to be closed (this will happen after we received the FIN).
// After this is done we will close the underlying datagram channel.
streamChannel.closeFuture().sync();
// After we received the response let's also close the underlying QUIC channel and datagram channel.
quicChannel.close().sync();
channel.close().sync();
} finally {
group.shutdownGracefully();
}
}
}
this is where client reject server initiated bi streams?
QuicChannel quicChannel = QuicChannel.newBootstrap(channel)
.handler(new Http3ClientConnectionHandler())
.remoteAddress(new InetSocketAddress(NetUtil.LOCALHOST4, Http3ServerExample.PORT))
.connect()
.get();
is any client like WebtransportClientHandler is extension of Http3ClientConnectionHandler NOT Http3ConnectionHandler ?? normanmaurer commented on Jun 30, 2026 @sanjomo so would this be good enough ?
diff --git a/codec-http3/src/main/java/io/netty/handler/codec/http3/Http3ClientConnectionHandler.java b/codec-http3/src/main/java/io/netty/handler/codec/http3/Http3ClientConnectionHandler.java
index c591d76281..1e902163d3 100644
--- a/codec-http3/src/main/java/io/netty/handler/codec/http3/Http3ClientConnectionHandler.java
+++ b/codec-http3/src/main/java/io/netty/handler/codec/http3/Http3ClientConnectionHandler.java
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.function.LongFunction;
-public final class Http3ClientConnectionHandler extends Http3ConnectionHandler {
+public class Http3ClientConnectionHandler extends Http3ConnectionHandler {
private final LongFunction<ChannelHandler> pushStreamHandlerFactory;
@@ -89,7 +89,7 @@ public final class Http3ClientConnectionHandler extends Http3ConnectionHandler {
}
@Override
- void initBidirectionalStream(ChannelHandlerContext ctx, QuicStreamChannel channel) {
+ protected void initBidirectionalStream(ChannelHandlerContext ctx, QuicStreamChannel channel) {
// See https://datatracker.ietf.org/doc/html/rfc9114#name-bidirectional-streams
// https://datatracker.ietf.org/doc/html/rfc9114#section-6.1-3
Http3CodecUtils.connectionError(ctx, Http3ErrorCode.H3_STREAM_CREATION_ERROR,
sanjomo commented on Jun 30, 2026 ContributorAuthor More actions @normanmaurer just to clarify, is the intention that users extend Http3ClientConnectionHandler and override initBidirectionalStream()?
If so, why isn't initUnidirectionalStream() also designed to be overridden? Currently, every server-initiated unidirectional stream gets a Http3UnidirectionalStreamInboundClientHandler added automatically:
@Override
void initUnidirectionalStream(ChannelHandlerContext ctx, QuicStreamChannel streamChannel) {
final long maxTableCapacity = maxTableCapacity();
streamChannel.pipeline().addLast(
new Http3UnidirectionalStreamInboundClientHandler(
codecFactory, nonStandardSettingsValidator,
localControlStreamHandler, remoteControlStreamHandler,
unknownInboundStreamHandlerFactory, pushStreamHandlerFactory,
() -> new QpackEncoderHandler(maxTableCapacity, qpackDecoder),
() -> new QpackDecoderHandler(qpackEncoder)));
}
In some use cases, these streams are no longer intended to be treated as HTTP/3 streams but simply as QuicStreamChannels, so applications may also need to customize or replace the default handler attached to unidirectional streams too. normanmaurer commented on Jun 30, 2026 @sanjomo we can also let this one be overridden that said at that point we might just do what you suggested in the first place and make Http3ConnectionHandler public and it's methods / constructors protected. WDYT ? sanjomo commented on Jun 30, 2026 ContributorAuthor More actions
@sanjomo we can also let this one be overridden that said at that point we might just do what you suggested in the first place and make Http3ConnectionHandler public and it's methods / constructors protected. WDYT ?
My preference would be to make Http3ClientConnectionHandler extensible by making the relevant methods and constructors protected. Since Http3ConnectionHandler is already public, it would also make sense to make its methods and constructors protected where appropriate. normanmaurer commented on Jun 30, 2026
@sanjomo we can also let this one be overridden that said at that point we might just do what you suggested in the first place and make Http3ConnectionHandler public and it's methods / constructors protected. WDYT ?
My preference would be to make Http3ClientConnectionHandler extensible by making the relevant methods and constructors protected. Since Http3ConnectionHandler is already public, it would also make sense to make its methods and constructors protected where appropriate.
but at this point you basically override everything... so what is the point ? sanjomo commented on Jun 30, 2026 ContributorAuthor More actions @normanmaurer I can first prototype the Http3ClientConnectionHandler approach in a fork to verify that it covers the required use cases. If it does, we can finalise the upstream API based on the results. normanmaurer commented on Jun 30, 2026 sanjomo commented on Jun 30, 2026 ContributorAuthor More actions @normanmaurer Please proceed.
Verification Checklist
By making Http3ClientConnectionHandler extensible (removing final) and making initBidirectionalStream and initUnidirectionalStream protected,
I verified the following:
- Creating external WebTransportClientHandler extending Http3ClientConnectionHandler
- Creating a CONNECT request.
- Sending and receiving capsules.
- Sending and receiving datagrams.
- Creating bidirectional and unidirectional streams from the client.
- Accepting bidirectional and unidirectional streams initiated by the server.
Proposed Changes
- Remove
final from Http3ClientConnectionHandler.
- Make
initBidirectionalStream(...) and initUnidirectionalStream(...) protected.
##Sample client handler
/**
* Webtransport client implementation
*/
public class WebTransportClientHandler extends Http3ClientConnectionHandler {
private Logger logger = LoggerFactory.getLogger(WebTransportClientHandler.class);
public WebTransportClientHandler() {
this(null, true, null);
}
public WebTransportClientHandler(
Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) {
this(localSettings,
disableQpackDynamicTable, null);
}
public WebTransportClientHandler(Http3SettingsFrame localSettings, boolean disableQpackDynamicTable,
Http3Settings.NonStandardHttp3SettingsValidator
nonStandardSettingsValidator) {
super(null, null, null, localSettings,
disableQpackDynamicTable, nonStandardSettingsValidator);
}
@Override
protected void initBidirectionalStream(ChannelHandlerContext ctx,
QuicStreamChannel channel) {
logger.info("Initializing bidirectional stream {}", channel.streamId());
channel.pipeline().addLast(new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof ByteBuf) {
ByteBuf buf = (ByteBuf) msg;
System.out.println("=== BIDI STREAM " + channel.streamId() + " ===");
System.out.println(io.netty.buffer.ByteBufUtil.prettyHexDump(buf));
System.out.println("ASCII: " +
buf.toString(buf.readerIndex(), buf.readableBytes(), CharsetUtil.UTF_8));
}
ctx.fireChannelRead(msg);
}
});
}
@Override
protected void initUnidirectionalStream(ChannelHandlerContext ctx,
QuicStreamChannel streamChannel) {
logger.info("Initializing unidirectional stream {}", streamChannel.streamId());
streamChannel.pipeline().addLast(new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof ByteBuf) {
ByteBuf buf = (ByteBuf) msg;
System.out.println("=== UNI STREAM " + streamChannel.streamId() + " ===");
System.out.println(io.netty.buffer.ByteBufUtil.prettyHexDump(buf));
System.out.println("ASCII: " +
buf.toString(buf.readerIndex(), buf.readableBytes(), CharsetUtil.UTF_8));
}
ctx.fireChannelRead(msg);
}
});
}
}
##Sample client
/**
* Sample Webtransport client
*/
public final class WebTransportClientExample {
private WebTransportClientExample() { }
public static void main(String... args) throws Exception {
EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory());
try {
QuicSslContext context = QuicSslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.applicationProtocols(Http3.supportedApplicationProtocols()).build();
ChannelHandler codec = Http3.newQuicClientCodecBuilder()
.sslContext(context)
.maxIdleTimeout(5000, TimeUnit.MILLISECONDS)
.initialMaxData(10000000)
.initialMaxStreamDataBidirectionalLocal(1000000)
.initialMaxStreamDataBidirectionalRemote(10000000)
.initialMaxStreamsUnidirectional(10000)
.initialMaxStreamDataUnidirectional(10000)
.initialMaxData(1000000000)
.initialMaxStreamsBidirectional(100000).datagram(10000,10000)
.build();
Bootstrap bs = new Bootstrap();
Channel channel = bs.group(group)
.channel(NioDatagramChannel.class)
.handler(codec)
.bind(0).sync().channel();
Http3Settings settings = new Http3Settings((id, value) -> true);
settings.enableConnectProtocol(true);
settings.enableH3Datagram(true);
QuicChannel quicChannel = QuicChannel.newBootstrap(channel)
.handler(new WebTransportClientHandler(new DefaultHttp3SettingsFrame(settings),
true,(id, value) -> true))
.remoteAddress(new InetSocketAddress(NetUtil.LOCALHOST4, 4433))
.connect()
.get();
QuicStreamChannel connectStreamChannel = Http3.newRequestStream(
quicChannel,
new ChannelDuplexHandler() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
try {
if (msg instanceof Http3HeadersFrame ) {
Http3HeadersFrame headers = (Http3HeadersFrame) msg;
System.out.println("Received headers: " + headers.headers());
} else if (msg instanceof Http3DataFrame) {
Http3DataFrame data = (Http3DataFrame) msg;
System.out.println("Received: " +
data.content().toString(CharsetUtil.UTF_8));
}
} finally {
ReferenceCountUtil.release(msg);
}
}
@Override
public void write(ChannelHandlerContext ctx,
Object msg,
ChannelPromise promise) throws Exception {
System.out.println("Writing: " + msg);
super.write(ctx, msg, promise);
}
}
).sync().getNow();
// Write the Header frame and send the FIN to mark the end of the request.
// After this it's not possible anymore to write any more data.
Http3HeadersFrame frame = new DefaultHttp3HeadersFrame();
frame.headers().method("CONNECT").path("/test")
.authority(NetUtil.LOCALHOST4.getHostAddress() + ":" + 4433)
.scheme("https").protocol("webtransport-h3");
connectStreamChannel.writeAndFlush(frame).sync();
long sessionid = connectStreamChannel.streamId();
quicChannel.createStream(
QuicStreamType.UNIDIRECTIONAL,
new ChannelInboundHandlerAdapter() {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
System.out.println("Stream active");
ByteBuf buf = ctx.alloc().buffer();
WebTransportUtils.writeVarInt(buf, 0x54);
WebTransportUtils.writeVarInt(buf, sessionid);
ctx.writeAndFlush(buf);
super.channelActive(ctx);
super.channelActive(ctx);
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
try {
System.out.println("Received: " + msg);
} finally {
ReferenceCountUtil.release(msg);
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
}
).sync().getNow();
quicChannel.createStream(
QuicStreamType.BIDIRECTIONAL,
new ChannelDuplexHandler() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
System.out.println("Channel read: " + msg);
}
@Override
public void write(ChannelHandlerContext ctx,
Object msg,
ChannelPromise promise) throws Exception {
System.out.println("Writing: " + msg);
super.write(ctx, msg, promise);
}
}
).sync().getNow();
WebTransportUtils.sendMaxStreamsCapsule(connectStreamChannel, false, 10000);
WebTransportUtils.sendMaxStreamsCapsule(connectStreamChannel, true, 10000);
WebTransportUtils.sendMaxDataCapsule(connectStreamChannel,1000000);
WebTransportUtils.sendStreamsBlockedCapsule(connectStreamChannel, false, 10000);
WebTransportUtils.sendStreamsBlockedCapsule(connectStreamChannel, true, 10000);
WebTransportUtils.sendDataBlockedCapsule(connectStreamChannel,1000000);
ByteBuf buffer = connectStreamChannel.parent().alloc().directBuffer();
WebTransportUtils.writeVarInt(buffer, connectStreamChannel.streamId() >> 2);
buffer.writeCharSequence("hello world", CharsetUtil.UTF_8);
connectStreamChannel.parent().writeAndFlush(buffer).sync();
} finally {
group.shutdownGracefully();
}
}
}
added 2 commits that reference this issue on Jul 1, 2026This issue will close once commit 0edad8e is merged into the '4.1' branch.0edad8e This issue will close once commit 7606a92 is merged into the '4.2' branch.7606a92
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|