From 92ea784712fe0b0534de672f20b34ae1d4009f17 Mon Sep 17 00:00:00 2001 From: Weidi Deng Date: Mon, 28 Apr 2025 18:21:40 +0800 Subject: [PATCH] return a net.Conn that implements connectionStater if applicable --- modules/caddyhttp/http2listener.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/caddyhttp/http2listener.go b/modules/caddyhttp/http2listener.go index b0bcbfe81..3ed65abe1 100644 --- a/modules/caddyhttp/http2listener.go +++ b/modules/caddyhttp/http2listener.go @@ -46,18 +46,27 @@ func (h *http2Listener) Accept() (net.Conn, error) { // if both h1 and h2 are enabled, we don't need to check the preface if h.useH1 && h.useH2 { - return &http2Conn{ - idx: len(http2.ClientPreface), - Conn: conn, - }, nil + return conn, nil } // impossible both are false, either useH1 or useH2 must be true, // or else the listener wouldn't be created - return &http2Conn{ + h2Conn := &http2Conn{ h2Expected: h.useH2, Conn: conn, - }, nil + } + if isConnectionStater { + return http2StateConn{h2Conn}, nil + } + return h2Conn, nil +} + +type http2StateConn struct { + *http2Conn +} + +func (conn http2StateConn) ConnectionState() tls.ConnectionState { + return conn.Conn.(connectionStater).ConnectionState() } type http2Conn struct {