return a net.Conn that implements connectionStater if applicable

This commit is contained in:
Weidi Deng 2025-04-28 18:21:40 +08:00 committed by WeidiDeng
parent 4c1922448b
commit 92ea784712
No known key found for this signature in database
GPG Key ID: 25F87CE1741EC7CD

View File

@ -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 both h1 and h2 are enabled, we don't need to check the preface
if h.useH1 && h.useH2 { if h.useH1 && h.useH2 {
return &http2Conn{ return conn, nil
idx: len(http2.ClientPreface),
Conn: conn,
}, nil
} }
// impossible both are false, either useH1 or useH2 must be true, // impossible both are false, either useH1 or useH2 must be true,
// or else the listener wouldn't be created // or else the listener wouldn't be created
return &http2Conn{ h2Conn := &http2Conn{
h2Expected: h.useH2, h2Expected: h.useH2,
Conn: conn, 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 { type http2Conn struct {