From f6fceffc3f162dbfe84b91a1c5d4d12001f2ccb3 Mon Sep 17 00:00:00 2001 From: alyssa Date: Sat, 11 May 2024 20:54:05 +0900 Subject: [PATCH] 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... --- PluralKit.Bot/Commands/ImportExport.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PluralKit.Bot/Commands/ImportExport.cs b/PluralKit.Bot/Commands/ImportExport.cs index 56973ecf..0b318622 100644 --- a/PluralKit.Bot/Commands/ImportExport.cs +++ b/PluralKit.Bot/Commands/ImportExport.cs @@ -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( content, _settings