diff options
| author | Bond_009 <bond.009@outlook.com> | 2024-10-31 17:02:06 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2024-10-31 17:02:06 +0100 |
| commit | d2db7004024c6bbdd541a381c673f1e0b0aebfcb (patch) | |
| tree | 48d21b619b13c73fc85988d7c0b33a816b4f2c02 /Jellyfin.Api/Formatters/CssOutputFormatter.cs | |
| parent | 282784cbb6fe203b87a6f2c673454ac8d3da82fa (diff) | |
Always await instead of directly returning Task
https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md#prefer-asyncawait-over-directly-returning-task
The performance impact is negligible (and it's me saying that!)
Diffstat (limited to 'Jellyfin.Api/Formatters/CssOutputFormatter.cs')
| -rw-r--r-- | Jellyfin.Api/Formatters/CssOutputFormatter.cs | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/Jellyfin.Api/Formatters/CssOutputFormatter.cs b/Jellyfin.Api/Formatters/CssOutputFormatter.cs index 495f771e1..9ad1c863e 100644 --- a/Jellyfin.Api/Formatters/CssOutputFormatter.cs +++ b/Jellyfin.Api/Formatters/CssOutputFormatter.cs @@ -1,6 +1,4 @@ -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; +using System.Net.Mime; using Microsoft.AspNetCore.Mvc.Formatters; namespace Jellyfin.Api.Formatters; @@ -8,28 +6,14 @@ namespace Jellyfin.Api.Formatters; /// <summary> /// Css output formatter. /// </summary> -public class CssOutputFormatter : TextOutputFormatter +public sealed class CssOutputFormatter : StringOutputFormatter { /// <summary> /// Initializes a new instance of the <see cref="CssOutputFormatter"/> class. /// </summary> public CssOutputFormatter() { - SupportedMediaTypes.Add("text/css"); - - SupportedEncodings.Add(Encoding.UTF8); - SupportedEncodings.Add(Encoding.Unicode); - } - - /// <summary> - /// Write context object to stream. - /// </summary> - /// <param name="context">Writer context.</param> - /// <param name="selectedEncoding">Unused. Writer encoding.</param> - /// <returns>Write stream task.</returns> - public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding) - { - var stringResponse = context.Object?.ToString(); - return stringResponse is null ? Task.CompletedTask : context.HttpContext.Response.WriteAsync(stringResponse); + SupportedMediaTypes.Clear(); + SupportedMediaTypes.Add(MediaTypeNames.Text.Css); } } |
