mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-09 21:00:58 +00:00
feat(sub): Add XHTTP session field compatibility in share links and subscriptions (#5929)
* ✨ Add sessionKey and sessionPlacement compatability for previous clients * ✨ Add sessionKey and sessionPlacement compatability for previous clients on backend
This commit is contained in:
@@ -2017,6 +2017,15 @@ func buildXhttpExtra(xhttp map[string]any) map[string]any {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Older clients still read the pre-#6258 names from the subscription
|
||||
// extra JSON. Emit aliases after lifting legacy inputs so both old and
|
||||
// new clients can consume the same link.
|
||||
if v, ok := extra["sessionIDPlacement"].(string); ok && len(v) > 0 {
|
||||
extra["sessionPlacement"] = v
|
||||
}
|
||||
if v, ok := extra["sessionIDKey"].(string); ok && len(v) > 0 {
|
||||
extra["sessionKey"] = v
|
||||
}
|
||||
|
||||
for _, field := range []string{"uplinkChunkSize"} {
|
||||
if v, ok := nonZeroShareValue(xhttp[field]); ok {
|
||||
|
||||
@@ -335,6 +335,8 @@ func TestBuildXhttpExtra_IncludesClientSideFieldsWhenPresent(t *testing.T) {
|
||||
"mode": "packet-up",
|
||||
"xPaddingBytes": "100-1000",
|
||||
"uplinkHTTPMethod": "GET",
|
||||
"sessionIDPlacement": "header",
|
||||
"sessionIDKey": "X-Session",
|
||||
"uplinkChunkSize": float64(4096),
|
||||
"noGRPCHeader": true,
|
||||
"scMinPostsIntervalMs": "20-40",
|
||||
@@ -375,6 +377,16 @@ func TestBuildXhttpExtra_IncludesClientSideFieldsWhenPresent(t *testing.T) {
|
||||
if extra["mode"] != "packet-up" {
|
||||
t.Fatalf("extra[mode] = %#v, want packet-up", extra["mode"])
|
||||
}
|
||||
for key, want := range map[string]string{
|
||||
"sessionIDPlacement": "header",
|
||||
"sessionIDKey": "X-Session",
|
||||
"sessionPlacement": "header",
|
||||
"sessionKey": "X-Session",
|
||||
} {
|
||||
if extra[key] != want {
|
||||
t.Fatalf("extra[%s] = %#v, want %q; extra %#v", key, extra[key], want, extra)
|
||||
}
|
||||
}
|
||||
|
||||
headers, ok := extra["headers"].(map[string]any)
|
||||
if !ok {
|
||||
@@ -388,6 +400,24 @@ func TestBuildXhttpExtra_IncludesClientSideFieldsWhenPresent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildXhttpExtra_LegacySessionFieldsEmitBothNames(t *testing.T) {
|
||||
extra := buildXhttpExtra(map[string]any{
|
||||
"sessionPlacement": "query",
|
||||
"sessionKey": "sess",
|
||||
})
|
||||
|
||||
for key, want := range map[string]string{
|
||||
"sessionIDPlacement": "query",
|
||||
"sessionIDKey": "sess",
|
||||
"sessionPlacement": "query",
|
||||
"sessionKey": "sess",
|
||||
} {
|
||||
if extra[key] != want {
|
||||
t.Fatalf("extra[%s] = %#v, want %q; extra %#v", key, extra[key], want, extra)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildXhttpExtra_LeavesDefaultClientSideFieldsOut(t *testing.T) {
|
||||
extra := buildXhttpExtra(map[string]any{
|
||||
"uplinkHTTPMethod": "",
|
||||
|
||||
Reference in New Issue
Block a user