From d867bb3b50eafe4e4cfc0a7ce25de47bc86fdace Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sun, 22 Aug 2021 16:03:46 +0800 Subject: [PATCH] Feature: support xray's ws-0rtt path (#1558) --- transport/vmess/websocket.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/transport/vmess/websocket.go b/transport/vmess/websocket.go index 956b6d95..7d7a75bb 100644 --- a/transport/vmess/websocket.go +++ b/transport/vmess/websocket.go @@ -11,6 +11,7 @@ import ( "net" "net/http" "net/url" + "strconv" "strings" "sync" "time" @@ -305,6 +306,18 @@ func streamWebsocketConn(conn net.Conn, c *WebsocketConfig, earlyData *bytes.Buf } func StreamWebsocketConn(conn net.Conn, c *WebsocketConfig) (net.Conn, error) { + if u, err := url.Parse(c.Path); err == nil { + if q := u.Query(); q.Get("ed") != "" { + if ed, err := strconv.Atoi(q.Get("ed")); err == nil { + c.MaxEarlyData = ed + c.EarlyDataHeaderName = "Sec-WebSocket-Protocol" + q.Del("ed") + u.RawQuery = q.Encode() + c.Path = u.String() + } + } + } + if c.MaxEarlyData > 0 { return streamWebsocketWithEarlyDataConn(conn, c) }