Cache headers

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Wave Dev 2026-03-13 11:15:31 +00:00 committed by GitHub
parent 06117adf47
commit eccc481b44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -74,6 +74,11 @@ public class DiscordClient(
if (tokenKind != TokenKind.Bot) if (tokenKind != TokenKind.Bot)
{ {
try try
{
// Cache headers from the external API so we don't make this request on every call.
static Dictionary<string, string>? cachedHeaders;
if (cachedHeaders is null)
{ {
using var apiReq = new HttpRequestMessage( using var apiReq = new HttpRequestMessage(
HttpMethod.Post, HttpMethod.Post,
@ -93,8 +98,8 @@ public class DiscordClient(
var properties = root.GetProperty("properties"); var properties = root.GetProperty("properties");
string userAgent = proprties.GetProperty("user_agent").GetString()!; string userAgent = properties.GetProperty("user_agent").GetString()!;
string browserVersion = proprties.GetProperty("browser_version").GetString()!; string browserVersion = properties.GetProperty("browser_version").GetString()!;
string osType = properties.GetProperty("os").GetString()!; string osType = properties.GetProperty("os").GetString()!;
string chromeMajor = browserVersion.Split('.')[0]; string chromeMajor = browserVersion.Split('.')[0];
@ -119,7 +124,10 @@ public class DiscordClient(
["x-super-properties"] = xspBase64, ["x-super-properties"] = xspBase64,
}; };
foreach (var kv in headers) cachedHeaders = headers;
}
foreach (var kv in cachedHeaders)
request.Headers.TryAddWithoutValidation(kv.Key, kv.Value); request.Headers.TryAddWithoutValidation(kv.Key, kv.Value);
} }
catch { } catch { }