From 6961633cc9e72dd9f2ed3b1c7fcee22112bf8a77 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Mon, 17 Apr 2023 22:04:09 +0300 Subject: [PATCH] Serve plain text files (eg. logs) as UTF-8 --- .../Frontend/Mappers/StaticResourceMapperBase.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Radarr.Http/Frontend/Mappers/StaticResourceMapperBase.cs b/src/Radarr.Http/Frontend/Mappers/StaticResourceMapperBase.cs index 402bce167..4a5992e8c 100644 --- a/src/Radarr.Http/Frontend/Mappers/StaticResourceMapperBase.cs +++ b/src/Radarr.Http/Frontend/Mappers/StaticResourceMapperBase.cs @@ -1,7 +1,9 @@ using System; using System.IO; +using System.Text; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.StaticFiles; +using Microsoft.Net.Http.Headers; using NLog; using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; @@ -39,7 +41,10 @@ public IActionResult GetResponse(string resourceUrl) contentType = "application/octet-stream"; } - return new FileStreamResult(GetContentStream(filePath), contentType); + return new FileStreamResult(GetContentStream(filePath), new MediaTypeHeaderValue(contentType) + { + Encoding = contentType == "text/plain" ? Encoding.UTF8 : null + }); } _logger.Warn("File {0} not found", filePath);