diff options
| author | Patrick Barron <barronpm@gmail.com> | 2023-01-13 22:23:22 -0500 |
|---|---|---|
| committer | Patrick Barron <barronpm@gmail.com> | 2023-01-15 15:46:50 -0500 |
| commit | 7186b343bd21fe6b4e771b8530bd780a98a84472 (patch) | |
| tree | 2d163788f83006d2480b2418045b9c640b71fef8 /Jellyfin.Api/Formatters/XmlOutputFormatter.cs | |
| parent | 74a07f6d1c52533aa648da27cb3924d6bb41bb19 (diff) | |
Move Formatters to Jellyfin.Api
Diffstat (limited to 'Jellyfin.Api/Formatters/XmlOutputFormatter.cs')
| -rw-r--r-- | Jellyfin.Api/Formatters/XmlOutputFormatter.cs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Jellyfin.Api/Formatters/XmlOutputFormatter.cs b/Jellyfin.Api/Formatters/XmlOutputFormatter.cs new file mode 100644 index 000000000..df8b1650b --- /dev/null +++ b/Jellyfin.Api/Formatters/XmlOutputFormatter.cs @@ -0,0 +1,33 @@ +using System.Net.Mime; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Formatters; + +namespace Jellyfin.Api.Formatters +{ + /// <summary> + /// Xml output formatter. + /// </summary> + public class XmlOutputFormatter : TextOutputFormatter + { + /// <summary> + /// Initializes a new instance of the <see cref="XmlOutputFormatter"/> class. + /// </summary> + public XmlOutputFormatter() + { + SupportedMediaTypes.Clear(); + SupportedMediaTypes.Add(MediaTypeNames.Text.Xml); + + SupportedEncodings.Add(Encoding.UTF8); + SupportedEncodings.Add(Encoding.Unicode); + } + + /// <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); + } + } +} |
