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
{
using var apiReq = new HttpRequestMessage(
HttpMethod.Post,
"https://cordapi.dolfi.es/api/v2/properties/web"
);
// Cache headers from the external API so we don't make this request on every call.
static Dictionary<string, string>? cachedHeaders;
using var apiRes = await Http.Client.SendAsync(apiReq, innerCancellationToken);
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>
if (cachedHeaders is null)
{
["sec-ch-ua-platform"] = $"\"{osType}\"",
["referer"] = "https://discord.com/app",
["x-debug-options"] = "bugReporterEnabled",
["accept-language"] = "en-US,en;q=0.9",
using var apiReq = new HttpRequestMessage(
HttpMethod.Post,
"https://cordapi.dolfi.es/api/v2/properties/web"
);
["sec-ch-ua"] =
$"\"Chromium\";v=\"{chromeMajor}\", \"Not;A=Brand\";v=\"99\"",
using var apiRes = await Http.Client.SendAsync(apiReq, innerCancellationToken);
apiRes.EnsureSuccessStatusCode();
["sec-ch-ua-mobile"] = "?0",
var apiJson = await apiRes.Content.ReadAsStringAsync(innerCancellationToken);
["x-discord-timezone"] = "Europe/Warsaw",
["x-context-properties"] = "eyJsb2NhdGlvbiI6Ii9hcHAifQ==",
["x-discord-locale"] = "en-US",
using var doc = JsonDocument.Parse(apiJson);
["user-agent"] = userAgent,
["x-super-properties"] = xspBase64,
};
var root = doc.RootElement;
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);
}
catch { }