Skip to content

Commit 6af42f1

Browse files
authored
fix(protocol): preserve VLESS HTTP upgrade URI options (#263)
1 parent 707ad4b commit 6af42f1

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

node/protocol/vless.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ func EncodeVLESSURL(v VLESS) string {
215215
if v.Query.EarlyDataHeader != "" {
216216
q.Set("eh", v.Query.EarlyDataHeader)
217217
}
218+
// 保留 HTTP Upgrade 扩展,避免 Mihomo 配置经 VLESS URI 往返转换后退化为普通 WebSocket。
219+
if v.Query.HttpUpgrade == 1 {
220+
q.Set("httpUpgrade", "1")
221+
}
222+
if v.Query.HttpUpgradeFastOpen == 1 {
223+
q.Set("httpUpgradeFastOpen", "1")
224+
}
218225

219226
// http传输层参数
220227
if v.Query.Method != "" {

node/protocol/vless_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ func TestVlessEncodeDecode(t *testing.T) {
1414
Server: "example.com",
1515
Port: 443,
1616
Query: VLESSQuery{
17-
Security: "tls",
18-
Encryption: "none",
19-
Type: "ws",
20-
Host: "cdn.example.com",
21-
Path: "/vless",
22-
Sni: "sni.example.com",
23-
Fp: "chrome",
24-
Fingerprint: "16dac3717024eb319093d1c95290c14adc850e2814b2208d11c7b7a436923859",
25-
Alpn: []string{"h2", "http/1.1"},
17+
Security: "tls",
18+
Encryption: "none",
19+
Type: "ws",
20+
Host: "cdn.example.com",
21+
Path: "/vless",
22+
Sni: "sni.example.com",
23+
Fp: "chrome",
24+
Fingerprint: "16dac3717024eb319093d1c95290c14adc850e2814b2208d11c7b7a436923859",
25+
Alpn: []string{"h2", "http/1.1"},
26+
HttpUpgrade: 1,
27+
HttpUpgradeFastOpen: 1,
2628
},
2729
}
2830

@@ -47,6 +49,8 @@ func TestVlessEncodeDecode(t *testing.T) {
4749
assertEqualString(t, "Query.Sni", original.Query.Sni, decoded.Query.Sni)
4850
assertEqualString(t, "Query.Fingerprint", original.Query.Fingerprint, decoded.Query.Fingerprint)
4951
assertEqualString(t, "Query.Path", original.Query.Path, decoded.Query.Path)
52+
assertEqualInt(t, "Query.HttpUpgrade", original.Query.HttpUpgrade, decoded.Query.HttpUpgrade)
53+
assertEqualInt(t, "Query.HttpUpgradeFastOpen", original.Query.HttpUpgradeFastOpen, decoded.Query.HttpUpgradeFastOpen)
5054

5155
t.Logf("✓ VLESS 编解码测试通过,名称: %s", decoded.Name)
5256
}

0 commit comments

Comments
 (0)