mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-31 17:43:04 -06:00
feat: add x-super-properties header
The x-super-properties header is an important header that contains info about the client with a launch signature. if this header is not provided, discord may flag requests and cause accounts to be banned/restricted
This commit is contained in:
parent
6647f90ced
commit
89a2dabf2d
|
|
@ -33,17 +33,41 @@ public class DiscordClient(
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return await Http.ResponseResiliencePipeline.ExecuteAsync(
|
return await Http.ResponseResiliencePipeline.ExecuteAsync(
|
||||||
async innerCancellationToken =>
|
async innerCancellationToken =>
|
||||||
{
|
{
|
||||||
using var request = new HttpRequestMessage(HttpMethod.Get, new Uri(_baseUri, url));
|
using var request = new HttpRequestMessage(HttpMethod.Get, new Uri(_baseUri, url));
|
||||||
|
|
||||||
// Don't validate because the token can have special characters
|
// Authorization header
|
||||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/828
|
|
||||||
request.Headers.TryAddWithoutValidation(
|
request.Headers.TryAddWithoutValidation(
|
||||||
"Authorization",
|
"Authorization",
|
||||||
tokenKind == TokenKind.Bot ? $"Bot {token}" : token
|
tokenKind == TokenKind.Bot ? $"Bot {token}" : token
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// add browser headers like x-super-properties and user-agent
|
||||||
|
// this is really important as discord flags requests that dont have valid xsp header
|
||||||
|
if (tokenKind != TokenKind.Bot)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var headersJson = await Http.Client.GetStringAsync(
|
||||||
|
"https://gist.githubusercontent.com/MinerPL/731977099ca84bef7ad0a66978010045/raw/stable.headers.json",
|
||||||
|
innerCancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
var userHeaders = JsonSerializer.Deserialize<Dictionary<string, string>>(headersJson);
|
||||||
|
if (userHeaders is not null)
|
||||||
|
{
|
||||||
|
foreach (var kv in userHeaders)
|
||||||
|
request.Headers.TryAddWithoutValidation(kv.Key, kv.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var response = await Http.Client.SendAsync(
|
var response = await Http.Client.SendAsync(
|
||||||
request,
|
request,
|
||||||
HttpCompletionOption.ResponseHeadersRead,
|
HttpCompletionOption.ResponseHeadersRead,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue