From a1c68a4346f603afc28f7b00d8d76f78591ab4e4 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Thu, 7 May 2026 18:46:34 +0800 Subject: [PATCH] chore: using new net/http api in reality client fallback --- component/tls/reality.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/component/tls/reality.go b/component/tls/reality.go index 664cff67d..33b4d6f4f 100644 --- a/component/tls/reality.go +++ b/component/tls/reality.go @@ -22,7 +22,6 @@ import ( "github.com/metacubex/http" "github.com/metacubex/randv2" - "github.com/metacubex/tls" utls "github.com/metacubex/utls" "golang.org/x/crypto/hkdf" ) @@ -134,11 +133,16 @@ func GetRealityConn(ctx context.Context, conn net.Conn, fingerprint UClientHello func realityClientFallback(uConn net.Conn, serverName string, fingerprint utls.ClientHelloID) { defer uConn.Close() + // use h2c mode to disallow the net/http fallback to http1.1 + protocols := new(http.Protocols) + protocols.SetUnencryptedHTTP2(true) client := http.Client{ - Transport: &http.Http2Transport{ - DialTLSContext: func(ctx context.Context, network, addr string, config *tls.Config) (net.Conn, error) { - return uConn, nil + Transport: &http.Transport{ + DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) { + type netConn struct{ net.Conn } // hide tls-type to skip ALPN check and force enter h2 mode + return netConn{uConn}, nil }, + Protocols: protocols, }, } request, err := http.NewRequest("GET", "https://"+serverName, nil)