jellyfin/Jellyfin.Api/Formatters/XmlOutputFormatter.cs

33 lines
980 B
C#
Raw Normal View History

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