aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Api/Formatters/XmlOutputFormatter.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Jellyfin.Api/Formatters/XmlOutputFormatter.cs')
-rw-r--r--Jellyfin.Api/Formatters/XmlOutputFormatter.cs33
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);
+ }
+ }
+}