Skip to content

Commit 007c337

Browse files
committed
feat: Converter support Xray HTTPUpgrade fast open path
1 parent 72d0948 commit 007c337

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

common/convert/converter.go

+25-2
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,38 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
330330

331331
vmess["h2-opts"] = h2Opts
332332

333-
case "ws":
333+
case "ws", "httpupgrade":
334334
headers := make(map[string]any)
335335
wsOpts := make(map[string]any)
336336
wsOpts["path"] = []string{"/"}
337337
if host, ok := values["host"]; ok && host != "" {
338338
headers["Host"] = host.(string)
339339
}
340340
if path, ok := values["path"]; ok && path != "" {
341-
wsOpts["path"] = path.(string)
341+
path := path.(string)
342+
pathURL, err := url.Parse(path)
343+
if err == nil {
344+
query := pathURL.Query()
345+
if earlyData := query.Get("ed"); earlyData != "" {
346+
med, err := strconv.Atoi(earlyData)
347+
if err == nil {
348+
switch network {
349+
case "ws":
350+
wsOpts["max-early-data"] = med
351+
wsOpts["early-data-header-name"] = "Sec-WebSocket-Protocol"
352+
case "httpupgrade":
353+
wsOpts["v2ray-http-upgrade-fast-open"] = true
354+
}
355+
query.Del("ed")
356+
pathURL.RawQuery = query.Encode()
357+
path = pathURL.String()
358+
}
359+
}
360+
if earlyDataHeader := query.Get("eh"); earlyDataHeader != "" {
361+
wsOpts["early-data-header-name"] = earlyDataHeader
362+
}
363+
}
364+
wsOpts["path"] = path
342365
}
343366
wsOpts["headers"] = headers
344367
vmess["ws-opts"] = wsOpts

common/convert/v.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func handleVShareLink(names map[string]int, url *url.URL, scheme string, proxy m
100100
h2Opts["headers"] = headers
101101
proxy["h2-opts"] = h2Opts
102102

103-
case "ws":
103+
case "ws", "httpupgrade":
104104
headers := make(map[string]any)
105105
wsOpts := make(map[string]any)
106106
headers["User-Agent"] = RandUserAgent()
@@ -113,7 +113,13 @@ func handleVShareLink(names map[string]int, url *url.URL, scheme string, proxy m
113113
if err != nil {
114114
return fmt.Errorf("bad WebSocket max early data size: %v", err)
115115
}
116-
wsOpts["max-early-data"] = med
116+
switch network {
117+
case "ws":
118+
wsOpts["max-early-data"] = med
119+
wsOpts["early-data-header-name"] = "Sec-WebSocket-Protocol"
120+
case "httpupgrade":
121+
wsOpts["v2ray-http-upgrade-fast-open"] = true
122+
}
117123
}
118124
if earlyDataHeader := query.Get("eh"); earlyDataHeader != "" {
119125
wsOpts["early-data-header-name"] = earlyDataHeader

docs/config.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ proxies: # socks5
383383
# headers:
384384
# custom: value
385385
# v2ray-http-upgrade: false
386+
# v2ray-http-upgrade-fast-open: false
386387

387388
- name: "ss4-shadow-tls"
388389
type: ss
@@ -461,6 +462,7 @@ proxies: # socks5
461462
# max-early-data: 2048
462463
# early-data-header-name: Sec-WebSocket-Protocol
463464
# v2ray-http-upgrade: false
465+
# v2ray-http-upgrade-fast-open: false
464466

465467
- name: "vmess-h2"
466468
type: vmess
@@ -589,6 +591,7 @@ proxies: # socks5
589591
headers:
590592
Host: example.com
591593
# v2ray-http-upgrade: false
594+
# v2ray-http-upgrade-fast-open: false
592595

593596
# Trojan
594597
- name: "trojan"
@@ -633,6 +636,7 @@ proxies: # socks5
633636
# headers:
634637
# Host: example.com
635638
# v2ray-http-upgrade: false
639+
# v2ray-http-upgrade-fast-open: false
636640

637641
- name: "trojan-xtls"
638642
type: trojan

transport/vmess/websocket.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ func StreamWebsocketConn(ctx context.Context, conn net.Conn, c *WebsocketConfig)
495495
}
496496
}
497497

498-
if c.MaxEarlyData > 0 {
498+
if c.MaxEarlyData > 0 && !c.V2rayHttpUpgrade {
499499
return streamWebsocketWithEarlyDataConn(conn, c)
500500
}
501501

0 commit comments

Comments
 (0)