From aec26bb76cec827f3c36ab669a101facbc6dd3b6 Mon Sep 17 00:00:00 2001 From: svghubio Date: Sun, 15 Mar 2026 16:25:47 +0100 Subject: [PATCH] Fix adding extra request headers --- .../Discord/DiscordClient.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/DiscordChatExporter.Core/Discord/DiscordClient.cs b/DiscordChatExporter.Core/Discord/DiscordClient.cs index c855ef3..8b02745 100644 --- a/DiscordChatExporter.Core/Discord/DiscordClient.cs +++ b/DiscordChatExporter.Core/Discord/DiscordClient.cs @@ -50,10 +50,9 @@ public class DiscordClient( // discord flags requests that don't look like a real browser if (tokenKind != TokenKind.Bot) { - try + await Task.Run(async () => { // Cache headers from the external API so we don't make this request on every call. - if (_cachedBrowserHeaders is null) { using var apiReq = new HttpRequestMessage( @@ -74,7 +73,7 @@ public class DiscordClient( var properties = root.GetProperty("properties"); - string userAgent = properties.GetProperty("user_agent").GetString()!; + string userAgent = properties.GetProperty("browser_user_agent").GetString()!; string browserVersion = properties.GetProperty("browser_version").GetString()!; string osType = properties.GetProperty("os").GetString()!; @@ -93,7 +92,6 @@ public class DiscordClient( ["sec-ch-ua-mobile"] = "?0", ["x-discord-timezone"] = "Europe/Warsaw", - ["x-context-properties"] = "eyJsb2NhdGlvbiI6Ii9hcHAifQ==", ["x-discord-locale"] = "en-US", ["user-agent"] = userAgent, @@ -103,10 +101,12 @@ public class DiscordClient( _cachedBrowserHeaders = headers; } - foreach (var kv in _cachedBrowserHeaders) - if (!request.Headers.Contains(kv.Key)) request.Headers.TryAddWithoutValidation(kv.Key, kv.Value); - } - catch { } + foreach (var kv in _cachedBrowserHeaders!) + { + if (!request.Headers.Contains(kv.Key)) + request.Headers.TryAddWithoutValidation(kv.Key, kv.Value); + } + }); } var response = await Http.Client.SendAsync( -- 2.53.0.windows.2