aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Formatters/CssOutputFormatter.cs
blob: e8dd48e4e61510d39d2af126811b7daede7d3e7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Formatters;

namespace Jellyfin.Server.Formatters
{
    /// <summary>
    /// Css output formatter.
    /// </summary>
    public class CssOutputFormatter : TextOutputFormatter
    {
        /// <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 == null ? Task.CompletedTask : context.HttpContext.Response.WriteAsync(stringResponse);
        }
    }
}