diff --git a/client/service.go b/client/service.go index b31e07ba..523a5c03 100644 --- a/client/service.go +++ b/client/service.go @@ -21,8 +21,10 @@ import ( "fmt" "io" "net" + "net/url" "runtime" "strconv" + "strings" "sync" "sync/atomic" "time" @@ -229,6 +231,17 @@ func (svr *Service) login() (conn net.Conn, session *fmux.Session, err error) { } address := net.JoinHostPort(svr.cfg.ServerAddr, strconv.Itoa(svr.cfg.ServerPort)) + if svr.cfg.Protocol == "websocket" { + // compatible: construct the websocket server addr + address = "ws://" + address + if _url, _err := url.Parse(svr.cfg.ServerAddr); _err == nil && len(_url.Scheme) > 0 { + // support the cfg.ServerAddr parameter with the URL format, i.e. wss://domain/path/ + address = svr.cfg.ServerAddr + } + // add the frp websocket special path + address = strings.TrimRight(address, "/") + frpNet.FrpWebsocketPath + } + conn, err = frpNet.ConnectServerByProxyWithTLS(svr.cfg.HTTPProxy, svr.cfg.Protocol, address, tlsConfig, svr.cfg.DisableCustomTLSFirstByte) if err != nil { return diff --git a/pkg/util/net/websocket.go b/pkg/util/net/websocket.go index 36b6440c..58c0b8d7 100644 --- a/pkg/util/net/websocket.go +++ b/pkg/util/net/websocket.go @@ -78,9 +78,8 @@ func (p *WebsocketListener) Addr() net.Addr { return p.ln.Addr() } -// addr: domain:port +// addr: url func ConnectWebsocketServer(addr string) (net.Conn, error) { - addr = "ws://" + addr + FrpWebsocketPath uri, err := url.Parse(addr) if err != nil { return nil, err