Apply utls in geodata

This commit is contained in:
Fangliding
2026-06-24 14:08:56 +08:00
parent ac04c445bd
commit 518a7efac2
+22 -6
View File
@@ -9,6 +9,7 @@ import (
"path/filepath" "path/filepath"
"time" "time"
utls "github.com/refraction-networking/utls"
"github.com/xtls/xray-core/common/errors" "github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/platform/filesystem" "github.com/xtls/xray-core/common/platform/filesystem"
@@ -59,11 +60,7 @@ func newDownloader(ctx context.Context, dispatcher routing.Dispatcher, outbound
} }
func newClient(baseCtx context.Context, dispatcher routing.Dispatcher, outbound string) *http.Client { func newClient(baseCtx context.Context, dispatcher routing.Dispatcher, outbound string) *http.Client {
return &http.Client{ dial := func(ctx context.Context, network, address string) (net.Conn, error) {
Transport: &http.Transport{
Proxy: nil,
DisableKeepAlives: true,
DialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
var conn net.Conn var conn net.Conn
err := task.Run(ctx, func() error { err := task.Run(ctx, func() error {
if tagged.Dialer == nil { if tagged.Dialer == nil {
@@ -86,8 +83,27 @@ func newClient(baseCtx context.Context, dispatcher routing.Dispatcher, outbound
return &idleConn{ return &idleConn{
Conn: conn, Conn: conn,
}, nil }, nil
}
return &http.Client{
Transport: &http.Transport{
Proxy: nil,
DisableKeepAlives: true,
DialContext: dial,
DialTLSContext: func(ctx context.Context, network, address string) (net.Conn, error) {
conn, err := dial(ctx, network, address)
if err != nil {
return nil, err
}
host, _, _ := net.SplitHostPort(address)
tlsConn := utls.UClient(conn, &utls.Config{ServerName: host}, utls.HelloChrome_Auto)
handshakeCtx, cancel := context.WithTimeout(ctx, idleTimeout)
defer cancel()
if err := tlsConn.HandshakeContext(handshakeCtx); err != nil {
conn.Close()
return nil, err
}
return tlsConn, nil
}, },
TLSHandshakeTimeout: idleTimeout,
ResponseHeaderTimeout: idleTimeout, ResponseHeaderTimeout: idleTimeout,
}, },
CheckRedirect: func(req *http.Request, via []*http.Request) error { CheckRedirect: func(req *http.Request, via []*http.Request) error {