diff --git a/common/netutil/netutil.go b/common/netutil/netutil.go index eb17331..61b30de 100644 --- a/common/netutil/netutil.go +++ b/common/netutil/netutil.go @@ -20,13 +20,17 @@ import ( // ConnectServer connects to the server with the given address. func ConnectServer(config config.Config) net.Conn { scheme := "ws" + host := config.ServerAddr if config.Protocol == "wss" { scheme = "wss" + host = config.TLSSni } - u := url.URL{Scheme: scheme, Host: config.ServerAddr, Path: config.WebSocketPath} + u := url.URL{Scheme: scheme, Host: host, Path: config.WebSocketPath} header := make(http.Header) header.Set("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36") - header.Set("key", config.Key) + if config.Key != "" { + header.Set("key", config.Key) + } tlsConfig := &tls.Config{ InsecureSkipVerify: config.TLSInsecureSkipVerify, } @@ -37,7 +41,11 @@ func ConnectServer(config config.Config) net.Conn { Header: ws.HandshakeHeaderHTTP(header), Timeout: time.Duration(config.Timeout) * time.Second, TLSConfig: tlsConfig, + NetDial: func(ctx context.Context, network, addr string) (net.Conn, error) { + return net.Dial(network, config.ServerAddr) + }, } + log.Printf("%v\n", dialer.TLSConfig) c, _, _, err := dialer.Dial(context.Background(), u.String()) if err != nil { log.Printf("[client] failed to dial websocket %s %v", u.String(), err)