diff --git a/transport/internet/websocket/config.go b/transport/internet/websocket/config.go index 5d15546f..93a8ad07 100644 --- a/transport/internet/websocket/config.go +++ b/transport/internet/websocket/config.go @@ -12,6 +12,17 @@ func (c *Config) IsConnectionReuse() bool { return c.ConnectionReuse.Enable } +func (c *Config) GetNormailzedPath() string { + path := c.Path + if len(path) == 0 { + return "/" + } + if path[0] != '/' { + return "/" + path + } + return path +} + func init() { common.Must(internet.RegisterProtocolConfigCreator(internet.TransportProtocol_WebSocket, func() interface{} { return new(Config) diff --git a/transport/internet/websocket/dialer.go b/transport/internet/websocket/dialer.go index b14ad866..61f803e9 100644 --- a/transport/internet/websocket/dialer.go +++ b/transport/internet/websocket/dialer.go @@ -74,7 +74,7 @@ func wsDial(ctx context.Context, dest v2net.Destination) (net.Conn, error) { if (protocol == "ws" && dest.Port == 80) || (protocol == "wss" && dest.Port == 443) { host = dest.Address.String() } - uri := protocol + "://" + host + "/" + wsSettings.Path + uri := protocol + "://" + host + wsSettings.GetNormailzedPath() conn, resp, err := dialer.Dial(uri, nil) if err != nil { diff --git a/transport/internet/websocket/hub.go b/transport/internet/websocket/hub.go index 1487bdba..d5b8b5f0 100644 --- a/transport/internet/websocket/hub.go +++ b/transport/internet/websocket/hub.go @@ -108,7 +108,7 @@ func (ln *Listener) listenws(address v2net.Address, port v2net.Port) error { go func() { http.Serve(listener, &requestHandler{ - path: "/" + ln.config.Path, + path: "/" + ln.config.GetNormailzedPath(), conns: ln.awaitingConns, }) }()