Skip to content

Commit 1aabe7e

Browse files
authored
XHTTP transport: Do not force trailing path / when both sessionID and seq are placed elsewhere (#6307)
#6385 (comment) #6307 (comment) Closes #6410
1 parent e4e7614 commit 1aabe7e

2 files changed

Lines changed: 72 additions & 8 deletions

File tree

transport/internet/splithttp/config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ func (c *Config) GetNormalizedPath() string {
2424
path = "/" + path
2525
}
2626

27-
if path[len(path)-1] != '/' {
28-
path = path + "/"
27+
if c.GetNormalizedSessionPlacement() == PlacementPath ||
28+
c.GetNormalizedSeqPlacement() == PlacementPath {
29+
if path[len(path)-1] != '/' {
30+
path = path + "/"
31+
}
2932
}
3033

3134
return path

transport/internet/splithttp/config_test.go

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,77 @@ package splithttp_test
33
import (
44
"testing"
55

6+
"github.com/stretchr/testify/assert"
67
. "github.com/xtls/xray-core/transport/internet/splithttp"
78
)
89

910
func Test_GetNormalizedPath(t *testing.T) {
10-
c := Config{
11-
Path: "/?world",
11+
tests := []struct {
12+
TestName string
13+
Path string
14+
SessionIDPlacement string
15+
SeqPlacement string
16+
Expected string
17+
}{
18+
{
19+
TestName: "default placement keeps trailing slash",
20+
Path: "/sh",
21+
Expected: "/sh/",
22+
},
23+
{
24+
TestName: "query string is stripped",
25+
Path: "/?world",
26+
Expected: "/",
27+
},
28+
{
29+
TestName: "both off path drops trailing slash",
30+
Path: "/stream",
31+
SessionIDPlacement: "query",
32+
SeqPlacement: "query",
33+
Expected: "/stream",
34+
},
35+
{
36+
TestName: "both off path keeps file-like path",
37+
Path: "/stream/filename.extension",
38+
SessionIDPlacement: "query",
39+
SeqPlacement: "header",
40+
Expected: "/stream/filename.extension",
41+
},
42+
{
43+
TestName: "seq in path keeps trailing slash",
44+
Path: "/stream",
45+
SessionIDPlacement: "query",
46+
Expected: "/stream/",
47+
},
48+
{
49+
TestName: "session in path keeps trailing slash",
50+
Path: "/stream",
51+
SeqPlacement: "cookie",
52+
Expected: "/stream/",
53+
},
54+
{
55+
TestName: "existing trailing slash preserved",
56+
Path: "/stream/",
57+
SessionIDPlacement: "query",
58+
SeqPlacement: "query",
59+
Expected: "/stream/",
60+
},
61+
{
62+
TestName: "root unchanged",
63+
Path: "/",
64+
SessionIDPlacement: "query",
65+
SeqPlacement: "query",
66+
Expected: "/",
67+
},
1268
}
13-
14-
path := c.GetNormalizedPath()
15-
if path != "/" {
16-
t.Error("Unexpected: ", path)
69+
for _, test := range tests {
70+
t.Run(test.TestName, func(t *testing.T) {
71+
c := Config{
72+
Path: test.Path,
73+
SessionIDPlacement: test.SessionIDPlacement,
74+
SeqPlacement: test.SeqPlacement,
75+
}
76+
assert.Equal(t, test.Expected, c.GetNormalizedPath())
77+
})
1778
}
1879
}

0 commit comments

Comments
 (0)