@@ -1826,6 +1826,14 @@ func isCommonNetReadError(err error) bool {
1826
1826
return false
1827
1827
}
1828
1828
1829
+ type tlsConn interface {
1830
+ net.Conn
1831
+ ConnectionState () tls.ConnectionState
1832
+ HandshakeContext (ctx context.Context ) error
1833
+ }
1834
+
1835
+ var _ tlsConn = & tls.Conn {}
1836
+
1829
1837
// Serve a new connection.
1830
1838
func (c * conn ) serve (ctx context.Context ) {
1831
1839
c .remoteAddr = c .rwc .RemoteAddr ().String ()
@@ -1851,7 +1859,7 @@ func (c *conn) serve(ctx context.Context) {
1851
1859
}
1852
1860
}()
1853
1861
1854
- if tlsConn , ok := c .rwc .(* tls. Conn ); ok {
1862
+ if tlsConn , ok := c .rwc .(tlsConn ); ok {
1855
1863
tlsTO := c .server .tlsHandshakeTimeout ()
1856
1864
if tlsTO > 0 {
1857
1865
dl := time .Now ().Add (tlsTO )
@@ -1884,7 +1892,11 @@ func (c *conn) serve(ctx context.Context) {
1884
1892
// from being run on these connections. This prevents closeIdleConns from
1885
1893
// closing such connections. See issue https://golang.org/issue/39776.
1886
1894
c .setState (c .rwc , StateActive , skipHooks )
1887
- fn (c .server , tlsConn , h )
1895
+ if realTLSConn , ok := c .rwc .(* tls.Conn ); ok {
1896
+ fn (c .server , realTLSConn , h )
1897
+ } else if proto == http2NextProtoTLS {
1898
+ c .server .h2ProtoHandler (c .server , tlsConn , h )
1899
+ }
1888
1900
}
1889
1901
return
1890
1902
}
@@ -2691,6 +2703,8 @@ type Server struct {
2691
2703
onShutdown []func ()
2692
2704
2693
2705
listenerGroup sync.WaitGroup
2706
+
2707
+ h2ProtoHandler func (hs * Server , c tlsConn , h Handler )
2694
2708
}
2695
2709
2696
2710
// Close immediately closes all active net.Listeners and any
@@ -3502,7 +3516,7 @@ func (globalOptionsHandler) ServeHTTP(w ResponseWriter, r *Request) {
3502
3516
// Requests come from ALPN protocol handlers.
3503
3517
type initALPNRequest struct {
3504
3518
ctx context.Context
3505
- c * tls. Conn
3519
+ c tlsConn
3506
3520
h serverHandler
3507
3521
}
3508
3522
0 commit comments