XHTTP transport: Do not force trailing path / when both sessionID and seq are placed elsewhere (#6307)

https://github.com/XTLS/Xray-core/discussions/6385#discussioncomment-17454120

https://github.com/XTLS/Xray-core/pull/6307#issuecomment-4917498294

Closes https://github.com/XTLS/Xray-core/issues/6410
This commit is contained in:
ivolfram
2026-07-08 17:59:19 +00:00
committed by GitHub
parent e4e7614c62
commit 1aabe7ea78
2 changed files with 72 additions and 8 deletions
+5 -2
View File
@@ -24,8 +24,11 @@ func (c *Config) GetNormalizedPath() string {
path = "/" + path path = "/" + path
} }
if path[len(path)-1] != '/' { if c.GetNormalizedSessionPlacement() == PlacementPath ||
path = path + "/" c.GetNormalizedSeqPlacement() == PlacementPath {
if path[len(path)-1] != '/' {
path = path + "/"
}
} }
return path return path
+67 -6
View File
@@ -3,16 +3,77 @@ package splithttp_test
import ( import (
"testing" "testing"
"github.com/stretchr/testify/assert"
. "github.com/xtls/xray-core/transport/internet/splithttp" . "github.com/xtls/xray-core/transport/internet/splithttp"
) )
func Test_GetNormalizedPath(t *testing.T) { func Test_GetNormalizedPath(t *testing.T) {
c := Config{ tests := []struct {
Path: "/?world", TestName string
Path string
SessionIDPlacement string
SeqPlacement string
Expected string
}{
{
TestName: "default placement keeps trailing slash",
Path: "/sh",
Expected: "/sh/",
},
{
TestName: "query string is stripped",
Path: "/?world",
Expected: "/",
},
{
TestName: "both off path drops trailing slash",
Path: "/stream",
SessionIDPlacement: "query",
SeqPlacement: "query",
Expected: "/stream",
},
{
TestName: "both off path keeps file-like path",
Path: "/stream/filename.extension",
SessionIDPlacement: "query",
SeqPlacement: "header",
Expected: "/stream/filename.extension",
},
{
TestName: "seq in path keeps trailing slash",
Path: "/stream",
SessionIDPlacement: "query",
Expected: "/stream/",
},
{
TestName: "session in path keeps trailing slash",
Path: "/stream",
SeqPlacement: "cookie",
Expected: "/stream/",
},
{
TestName: "existing trailing slash preserved",
Path: "/stream/",
SessionIDPlacement: "query",
SeqPlacement: "query",
Expected: "/stream/",
},
{
TestName: "root unchanged",
Path: "/",
SessionIDPlacement: "query",
SeqPlacement: "query",
Expected: "/",
},
} }
for _, test := range tests {
path := c.GetNormalizedPath() t.Run(test.TestName, func(t *testing.T) {
if path != "/" { c := Config{
t.Error("Unexpected: ", path) Path: test.Path,
SessionIDPlacement: test.SessionIDPlacement,
SeqPlacement: test.SeqPlacement,
}
assert.Equal(t, test.Expected, c.GetNormalizedPath())
})
} }
} }