Files
jellyfin-jellyfin-1/Jellyfin.Api/Formatters/XmlOutputFormatter.cs

43 lines
1.2 KiB
C#
Raw Normal View History

2025-10-24 17:56:38 -06:00
using System;
using System.Net.Mime;
2025-10-24 17:56:38 -06:00
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
2020-08-15 10:39:24 -06:00
using Microsoft.AspNetCore.Mvc.Formatters;
2023-01-31 12:18:10 +01:00
namespace Jellyfin.Api.Formatters;
/// <summary>
/// Xml output formatter.
/// </summary>
2025-10-24 17:56:38 -06:00
public sealed class XmlOutputFormatter : TextOutputFormatter
2020-08-15 10:39:24 -06:00
{
/// <summary>
2023-01-31 12:18:10 +01:00
/// Initializes a new instance of the <see cref="XmlOutputFormatter"/> class.
2020-08-15 10:39:24 -06:00
/// </summary>
2023-01-31 12:18:10 +01:00
public XmlOutputFormatter()
2020-08-15 10:39:24 -06:00
{
2023-01-31 12:18:10 +01:00
SupportedMediaTypes.Clear();
SupportedMediaTypes.Add(MediaTypeNames.Text.Xml);
2025-10-24 17:56:38 -06:00
SupportedEncodings.Add(Encoding.UTF8);
SupportedEncodings.Add(Encoding.Unicode);
}
/// <inheritdoc />
public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
{
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(selectedEncoding);
var valueAsString = context.Object?.ToString();
if (string.IsNullOrEmpty(valueAsString))
{
return;
}
var response = context.HttpContext.Response;
await response.WriteAsync(valueAsString, selectedEncoding).ConfigureAwait(false);
2020-08-15 10:39:24 -06:00
}
}