From 493b8c24093cf27ec43f5c22ead5109c9ee7941e Mon Sep 17 00:00:00 2001 From: ayn2op Date: Tue, 16 Jun 2026 01:35:46 -0400 Subject: [PATCH] refactor(http): split discord client properties --- internal/http/headers.go | 8 ++-- internal/http/{props.go => properties.go} | 45 +++++++++-------------- 2 files changed, 23 insertions(+), 30 deletions(-) rename internal/http/{props.go => properties.go} (64%) diff --git a/internal/http/headers.go b/internal/http/headers.go index ed8cf76..c574b8c 100644 --- a/internal/http/headers.go +++ b/internal/http/headers.go @@ -1,6 +1,8 @@ package http import ( + "encoding/base64" + "encoding/json" "log/slog" stdHttp "net/http" @@ -24,11 +26,11 @@ func Headers() stdHttp.Header { headers.Set("X-Debug-Options", "bugReporterEnabled") headers.Set("X-Discord-Locale", string(Locale)) - superProps, err := getSuperProps() + superProps, err := json.Marshal(XSuperProperties()) if err != nil { - slog.Error("failed to get super props", "err", err) + slog.Error("failed to marshal super props", "err", err) } else { - headers.Set("X-Super-Properties", superProps) + headers.Set("X-Super-Properties", base64.StdEncoding.EncodeToString(superProps)) } return headers diff --git a/internal/http/props.go b/internal/http/properties.go similarity index 64% rename from internal/http/props.go rename to internal/http/properties.go index 127b054..10b5778 100644 --- a/internal/http/props.go +++ b/internal/http/properties.go @@ -1,9 +1,6 @@ package http import ( - "encoding/base64" - "encoding/json" - "github.com/diamondburned/arikawa/v3/discord" "github.com/diamondburned/arikawa/v3/gateway" "github.com/google/uuid" @@ -22,7 +19,7 @@ const ( Locale = discord.EnglishUS ) -func IdentifyProperties() gateway.IdentifyProperties { +func CommonProperties() gateway.IdentifyProperties { return gateway.IdentifyProperties{ gateway.IdentifyDevice: "", @@ -33,39 +30,33 @@ func IdentifyProperties() gateway.IdentifyProperties { "browser_version": BrowserVersion, "browser_user_agent": BrowserUserAgent, - "client_build_number": ClientBuildNumber, - "client_event_source": nil, - "client_app_state": "focused", - "client_launch_id": uuid.NewString(), - "client_heartbeat_session_id": uuid.NewString(), + "client_build_number": ClientBuildNumber, + "client_event_source": nil, + "client_launch_id": uuid.NewString(), - "launch_signature": generateLaunchSignature(), - "system_locale": Locale, - "release_channel": "stable", - "has_client_mods": false, + "system_locale": Locale, + "release_channel": "stable", + "has_client_mods": false, "referrer": "", "referrer_current": "", "referring_domain": "", "referring_domain_current": "", - - // These properties are only sent when identifying with the gateway and are not included in the X-Super-Properties header. - "is_fast_connect": false, - "gateway_connect_reasons": "AppSkeleton", } } -func getSuperProps() (string, error) { - props := IdentifyProperties() - delete(props, "is_fast_connect") - delete(props, "gateway_connect_reasons") +func IdentifyProperties() gateway.IdentifyProperties { + props := CommonProperties() + props["is_fast_connect"] = true + return props +} - raw, err := json.Marshal(props) - if err != nil { - return "", err - } - - return base64.StdEncoding.EncodeToString(raw), nil +func XSuperProperties() gateway.IdentifyProperties { + props := CommonProperties() + props["client_app_state"] = "focused" + props["client_heartbeat_session_id"] = uuid.NewString() + props["launch_signature"] = generateLaunchSignature() + return props } func generateLaunchSignature() string {