enable use cdn edge ip to accelerate cdn transport when wss

This commit is contained in:
catbestme 2024-07-02 18:42:24 +08:00
parent 41ccf890e9
commit d88b518034
2 changed files with 11 additions and 0 deletions

View File

@ -170,6 +170,7 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
wsOpts.WriteBufferSize = node.GetInt("wbuf") wsOpts.WriteBufferSize = node.GetInt("wbuf")
wsOpts.UserAgent = node.Get("agent") wsOpts.UserAgent = node.Get("agent")
wsOpts.Path = node.Get("path") wsOpts.Path = node.Get("path")
wsOpts.Host = node.Get("host")
timeout := node.GetDuration("timeout") timeout := node.GetDuration("timeout")

10
ws.go
View File

@ -5,6 +5,7 @@ import (
"crypto/sha1" "crypto/sha1"
"crypto/tls" "crypto/tls"
"encoding/base64" "encoding/base64"
"fmt"
"io" "io"
"net" "net"
"net/http" "net/http"
@ -31,6 +32,7 @@ type WSOptions struct {
EnableCompression bool EnableCompression bool
UserAgent string UserAgent string
Path string Path string
Host string
} }
type wsTransporter struct { type wsTransporter struct {
@ -749,6 +751,14 @@ func websocketClientConn(url string, conn net.Conn, tlsConfig *tls.Config, optio
if options.UserAgent != "" { if options.UserAgent != "" {
header.Set("User-Agent", 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) c, resp, err := dialer.Dial(url, header)
if err != nil { if err != nil {
return nil, err return nil, err