fix(bot): reset content-type header before reading content

Discord CDN sometimes returns content-type headers that not only break json
deserializing, but also just reading the body...
This commit is contained in:
alyssa 2024-05-11 20:54:05 +09:00
parent 8f3fa62ec3
commit f6fceffc3f

View file

@ -45,6 +45,9 @@ public class ImportExport
try
{
var response = await _client.GetAsync(url);
// hacky fix for discord api returning nonsense charsets sometimes
response.Content.Headers.Remove("content-type");
response.Content.Headers.Add("content-type", "application/json; charset=UTF-8");
var content = await response.Content.ReadAsStringAsync();
if (content == "This content is no longer available.")
{
@ -54,9 +57,6 @@ public class ImportExport
}
if (!response.IsSuccessStatusCode)
throw Errors.InvalidImportFile;
// hacky fix for discord api returning nonsense charsets sometimes
response.Content.Headers.Remove("content-type");
response.Content.Headers.Add("content-type", "application/json; charset=UTF-8");
data = JsonConvert.DeserializeObject<JObject>(
content,
_settings