| | | 1 | | using System; |
| | | 2 | | using System.Net.Mime; |
| | | 3 | | using System.Text; |
| | | 4 | | using System.Threading.Tasks; |
| | | 5 | | using Microsoft.AspNetCore.Http; |
| | | 6 | | using Microsoft.AspNetCore.Mvc.Formatters; |
| | | 7 | | |
| | | 8 | | namespace Jellyfin.Api.Formatters; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Xml output formatter. |
| | | 12 | | /// </summary> |
| | | 13 | | public sealed class XmlOutputFormatter : TextOutputFormatter |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// Initializes a new instance of the <see cref="XmlOutputFormatter"/> class. |
| | | 17 | | /// </summary> |
| | 21 | 18 | | public XmlOutputFormatter() |
| | | 19 | | { |
| | 21 | 20 | | SupportedMediaTypes.Clear(); |
| | 21 | 21 | | SupportedMediaTypes.Add(MediaTypeNames.Text.Xml); |
| | | 22 | | |
| | 21 | 23 | | SupportedEncodings.Add(Encoding.UTF8); |
| | 21 | 24 | | SupportedEncodings.Add(Encoding.Unicode); |
| | 21 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | | 28 | | public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding) |
| | | 29 | | { |
| | | 30 | | ArgumentNullException.ThrowIfNull(context); |
| | | 31 | | ArgumentNullException.ThrowIfNull(selectedEncoding); |
| | | 32 | | |
| | | 33 | | var valueAsString = context.Object?.ToString(); |
| | | 34 | | if (string.IsNullOrEmpty(valueAsString)) |
| | | 35 | | { |
| | | 36 | | return; |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | var response = context.HttpContext.Response; |
| | | 40 | | await response.WriteAsync(valueAsString, selectedEncoding).ConfigureAwait(false); |
| | | 41 | | } |
| | | 42 | | } |