From bb2f57b0e4b20cdef0c786e46e2e53f0a6771afb Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Fri, 8 May 2026 17:37:05 +0800 Subject: [PATCH] chore: using new net/http api in xhttp client --- transport/xhttp/client.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/transport/xhttp/client.go b/transport/xhttp/client.go index 08efc3599..96c7409cb 100644 --- a/transport/xhttp/client.go +++ b/transport/xhttp/client.go @@ -202,8 +202,11 @@ func NewTransport(dialRaw DialRawFunc, wrapTLS WrapTLSFunc, dialQUIC DialQUICFun if keepAlivePeriod < 0 { keepAlivePeriod = 0 } - return &http.Http2Transport{ - DialTLSContext: func(ctx context.Context, network, addr string, _ *tls.Config) (net.Conn, error) { + // use h2c mode to disallow the net/http fallback to http1.1 + protocols := new(http.Protocols) + protocols.SetUnencryptedHTTP2(true) + return &http.Transport{ + DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) { raw, err := dialRaw(ctx) if err != nil { return nil, err @@ -213,10 +216,14 @@ func NewTransport(dialRaw DialRawFunc, wrapTLS WrapTLSFunc, dialQUIC DialQUICFun _ = raw.Close() return nil, err } - return wrapped, nil + type netConn struct{ net.Conn } // hide tls-type to skip ALPN check and force enter h2 mode + return netConn{wrapped}, nil }, IdleConnTimeout: ConnIdleTimeout, - ReadIdleTimeout: keepAlivePeriod, + Protocols: protocols, + HTTP2: &http.HTTP2Config{ + SendPingTimeout: keepAlivePeriod, + }, } }