From d88b518034c56478804bfb2d33e3eaf72ed75b5c Mon Sep 17 00:00:00 2001 From: catbestme Date: Tue, 2 Jul 2024 18:42:24 +0800 Subject: [PATCH] enable use cdn edge ip to accelerate cdn transport when wss --- cmd/gost/route.go | 1 + ws.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/cmd/gost/route.go b/cmd/gost/route.go index 360bc2d..4b3a47c 100644 --- a/cmd/gost/route.go +++ b/cmd/gost/route.go @@ -170,6 +170,7 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) { wsOpts.WriteBufferSize = node.GetInt("wbuf") wsOpts.UserAgent = node.Get("agent") wsOpts.Path = node.Get("path") + wsOpts.Host = node.Get("host") timeout := node.GetDuration("timeout") diff --git a/ws.go b/ws.go index 9dc8f0d..5f49e99 100644 --- a/ws.go +++ b/ws.go @@ -5,6 +5,7 @@ import ( "crypto/sha1" "crypto/tls" "encoding/base64" + "fmt" "io" "net" "net/http" @@ -31,6 +32,7 @@ type WSOptions struct { EnableCompression bool UserAgent string Path string + Host string } type wsTransporter struct { @@ -749,6 +751,14 @@ func websocketClientConn(url string, conn net.Conn, tlsConfig *tls.Config, optio if options.UserAgent != "" { header.Set("User-Agent", options.UserAgent) } + if options.Host != "" { + fmt.Println("获取到命令行传参host==>", options.Host) + dialer.TLSClientConfig.ServerName = options.Host + header.Set("Host", options.Host) + } + + fmt.Printf("TLSClientConfig==>%+v\n", dialer.TLSClientConfig) + c, resp, err := dialer.Dial(url, header) if err != nil { return nil, err