Pārlūkot izejas kodu

normalized path in websocket

Darien Raymond 8 gadi atpakaļ
vecāks
revīzija
1aeab3dd96

+ 11 - 0
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)

+ 1 - 1
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 {

+ 1 - 1
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,
 		})
 	}()