From 2d4e91c5a202aeb7b5d6d2206767d05a8f850212 Mon Sep 17 00:00:00 2001 From: crobibero Date: Sat, 15 Aug 2020 10:39:24 -0600 Subject: [PATCH] Add xml output formatter --- .../ApiServiceCollectionExtensions.cs | 1 + .../Formatters/XmlOutputFormatter.cs | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 Jellyfin.Server/Formatters/XmlOutputFormatter.cs diff --git a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs index 83d8fac5b5..2e2bfea684 100644 --- a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs +++ b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs @@ -154,6 +154,7 @@ namespace Jellyfin.Server.Extensions opts.OutputFormatters.Insert(0, new PascalCaseJsonProfileFormatter()); opts.OutputFormatters.Add(new CssOutputFormatter()); + opts.OutputFormatters.Add(new XmlOutputFormatter()); }) // Clear app parts to avoid other assemblies being picked up diff --git a/Jellyfin.Server/Formatters/XmlOutputFormatter.cs b/Jellyfin.Server/Formatters/XmlOutputFormatter.cs new file mode 100644 index 0000000000..5f2337b2a2 --- /dev/null +++ b/Jellyfin.Server/Formatters/XmlOutputFormatter.cs @@ -0,0 +1,30 @@ +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Formatters; + +namespace Jellyfin.Server.Formatters +{ + /// + /// Xml output formatter. + /// + public class XmlOutputFormatter : TextOutputFormatter + { + /// + /// Initializes a new instance of the class. + /// + public XmlOutputFormatter() + { + SupportedMediaTypes.Add("text/xml"); + SupportedMediaTypes.Add("text/xml;charset=UTF-8"); + SupportedEncodings.Add(Encoding.UTF8); + SupportedEncodings.Add(Encoding.Unicode); + } + + /// + public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding) + { + return context.HttpContext.Response.WriteAsync(context.Object?.ToString()); + } + } +}