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

@ -75,51 +75,59 @@ public class DiscordClient(
{ {
try try
{ {
using var apiReq = new HttpRequestMessage( // Cache headers from the external API so we don't make this request on every call.
HttpMethod.Post, static Dictionary<string, string>? cachedHeaders;
"https://cordapi.dolfi.es/api/v2/properties/web"
);
using var apiRes = await Http.Client.SendAsync(apiReq, innerCancellationToken); if (cachedHeaders is null)
apiRes.EnsureSuccessStatusCode();
var apiJson = await apiRes.Content.ReadAsStringAsync(innerCancellationToken);
using var doc = JsonDocument.Parse(apiJson);
var root = doc.RootElement;
string xspBase64 = root.GetProperty("encoded").GetString()!;
var properties = root.GetProperty("properties");
string userAgent = proprties.GetProperty("user_agent").GetString()!;
string browserVersion = proprties.GetProperty("browser_version").GetString()!;
string osType = properties.GetProperty("os").GetString()!;
string chromeMajor = browserVersion.Split('.')[0];
var headers = new Dictionary<string, string>
{ {
["sec-ch-ua-platform"] = $"\"{osType}\"", using var apiReq = new HttpRequestMessage(
["referer"] = "https://discord.com/app", HttpMethod.Post,
["x-debug-options"] = "bugReporterEnabled", "https://cordapi.dolfi.es/api/v2/properties/web"
["accept-language"] = "en-US,en;q=0.9", );
["sec-ch-ua"] = using var apiRes = await Http.Client.SendAsync(apiReq, innerCancellationToken);
$"\"Chromium\";v=\"{chromeMajor}\", \"Not;A=Brand\";v=\"99\"", apiRes.EnsureSuccessStatusCode();
["sec-ch-ua-mobile"] = "?0", var apiJson = await apiRes.Content.ReadAsStringAsync(innerCancellationToken);
["x-discord-timezone"] = "Europe/Warsaw", using var doc = JsonDocument.Parse(apiJson);
["x-context-properties"] = "eyJsb2NhdGlvbiI6Ii9hcHAifQ==",
["x-discord-locale"] = "en-US",
["user-agent"] = userAgent, var root = doc.RootElement;
["x-super-properties"] = xspBase64,
};
foreach (var kv in headers) string xspBase64 = root.GetProperty("encoded").GetString()!;
var properties = root.GetProperty("properties");
string userAgent = properties.GetProperty("user_agent").GetString()!;
string browserVersion = properties.GetProperty("browser_version").GetString()!;
string osType = properties.GetProperty("os").GetString()!;
string chromeMajor = browserVersion.Split('.')[0];
var headers = new Dictionary<string, string>
{
["sec-ch-ua-platform"] = $"\"{osType}\"",
["referer"] = "https://discord.com/app",
["x-debug-options"] = "bugReporterEnabled",
["accept-language"] = "en-US,en;q=0.9",
["sec-ch-ua"] =
$"\"Chromium\";v=\"{chromeMajor}\", \"Not;A=Brand\";v=\"99\"",
["sec-ch-ua-mobile"] = "?0",
["x-discord-timezone"] = "Europe/Warsaw",
["x-context-properties"] = "eyJsb2NhdGlvbiI6Ii9hcHAifQ==",
["x-discord-locale"] = "en-US",
["user-agent"] = userAgent,
["x-super-properties"] = xspBase64,
};
cachedHeaders = headers;
}
foreach (var kv in cachedHeaders)
request.Headers.TryAddWithoutValidation(kv.Key, kv.Value); request.Headers.TryAddWithoutValidation(kv.Key, kv.Value);
} }
catch { } catch { }