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:
Maksim Alekseev
2026-07-28 23:15:28 +03:00
committed by GitHub
parent ff954ec48c
commit 041476a317
4 changed files with 119 additions and 2 deletions
+9
View File
@@ -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 {
+30
View File
@@ -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": "",