mirror of https://github.com/jellyfin/jellyfin
Backport pull request #15164 from jellyfin/release-10.11.z
Fix XmlOutputFormatter
Original-merge: 2b94bb54aa
Merged-by: crobibero <cody@robibe.ro>
Backported-by: Bond_009 <bond.009@outlook.com>
This commit is contained in:
parent
dbb015441f
commit
232c0399e2
|
|
@ -1,4 +1,8 @@
|
||||||
|
using System;
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
|
||||||
namespace Jellyfin.Api.Formatters;
|
namespace Jellyfin.Api.Formatters;
|
||||||
|
|
@ -6,7 +10,7 @@ namespace Jellyfin.Api.Formatters;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Xml output formatter.
|
/// Xml output formatter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class XmlOutputFormatter : StringOutputFormatter
|
public sealed class XmlOutputFormatter : TextOutputFormatter
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="XmlOutputFormatter"/> class.
|
/// Initializes a new instance of the <see cref="XmlOutputFormatter"/> class.
|
||||||
|
|
@ -15,5 +19,24 @@ public sealed class XmlOutputFormatter : StringOutputFormatter
|
||||||
{
|
{
|
||||||
SupportedMediaTypes.Clear();
|
SupportedMediaTypes.Clear();
|
||||||
SupportedMediaTypes.Add(MediaTypeNames.Text.Xml);
|
SupportedMediaTypes.Add(MediaTypeNames.Text.Xml);
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue