UTLS兼容
This commit is contained in:
+18
-4
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/go-gost/x/internal/net/proxyproto"
|
||||
ws_util "github.com/go-gost/x/internal/util/ws"
|
||||
"github.com/go-gost/x/registry"
|
||||
"github.com/go-gost/x/util"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
@@ -110,13 +111,26 @@ func (d *wsDialer) Handshake(ctx context.Context, conn net.Conn, options ...dial
|
||||
},
|
||||
}
|
||||
|
||||
url := url.URL{Scheme: "ws", Host: host, Path: d.md.path}
|
||||
urlObj := url.URL{Scheme: "ws", Host: host, Path: d.md.path}
|
||||
if d.tlsEnabled {
|
||||
url.Scheme = "wss"
|
||||
urlObj.Scheme = "wss"
|
||||
dialer.TLSClientConfig = d.options.TLSConfig
|
||||
dialer.NetDialTLSContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
client, err := util.NewUTLSWebSocketClient(conn, d.options.TLSConfig, d.md.useH2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := client.Handshake(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
}
|
||||
|
||||
c, resp, err := dialer.DialContext(ctx, url.String(), d.md.header)
|
||||
urlStr, errUnescape := url.QueryUnescape(urlObj.String())
|
||||
if errUnescape != nil {
|
||||
d.options.Logger.Debugf("[ws] URL QueryUnescape Error URL.String() -> %s", urlObj.String())
|
||||
}
|
||||
c, resp, err := dialer.DialContext(ctx, urlStr, d.md.header)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -14,8 +14,9 @@ const (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
host string
|
||||
path string
|
||||
host string
|
||||
path string
|
||||
useH2 bool
|
||||
|
||||
handshakeTimeout time.Duration
|
||||
readHeaderTimeout time.Duration
|
||||
@@ -66,5 +67,6 @@ func (d *wsDialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||
d.md.tcpKeepaliveInterval = mdutil.GetDuration(md, "tcp.keepalive.interval")
|
||||
d.md.tcpKeepaliveCount = mdutil.GetInt(md, "tcp.keepalive.count")
|
||||
|
||||
d.md.useH2 = mdutil.GetBool(md, "h2")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user