jellyfin/Jellyfin.Api/Formatters/XmlOutputFormatter.cs

34 lines
1 KiB
C#
Raw Normal View History

2020-08-16 19:48:54 +02:00
using System.Net.Mime;
using System.Text;
2020-08-15 18:39:24 +02:00
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Formatters;
2023-01-14 04:23:22 +01:00
namespace Jellyfin.Api.Formatters
2020-08-15 18:39:24 +02:00
{
/// <summary>
/// Xml output formatter.
/// </summary>
public class XmlOutputFormatter : TextOutputFormatter
{
/// <summary>
/// Initializes a new instance of the <see cref="XmlOutputFormatter"/> class.
/// </summary>
public XmlOutputFormatter()
{
2020-08-20 19:17:27 +02:00
SupportedMediaTypes.Clear();
2020-08-16 19:48:54 +02:00
SupportedMediaTypes.Add(MediaTypeNames.Text.Xml);
2020-08-20 19:17:27 +02:00
2020-08-15 18:39:24 +02:00
SupportedEncodings.Add(Encoding.UTF8);
SupportedEncodings.Add(Encoding.Unicode);
}
/// <inheritdoc />
public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
{
var stringResponse = context.Object?.ToString();
2022-12-05 15:00:20 +01:00
return stringResponse is null ? Task.CompletedTask : context.HttpContext.Response.WriteAsync(stringResponse);
2020-08-15 18:39:24 +02:00
}
}
}