fixed rss xml encoding always being utf-16

This commit is contained in:
Mia Rose Winter 2024-02-04 13:14:32 +01:00
parent 4e521145dd
commit 38e58f7b71
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E

View file

@ -13,6 +13,7 @@ public class SyndicationFeedFormatter : TextOutputFormatter {
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/atom+xml"));
SupportedEncodings.Add(Encoding.UTF8);
SupportedEncodings.Add(Encoding.Unicode);
}
protected override bool CanWriteType(Type? type)
@ -23,10 +24,10 @@ protected override bool CanWriteType(Type? type)
httpContext.Response.Headers.ContentDisposition = "inline";
var feed = context.Object as SyndicationFeed;
await using var stringWriter = new StringWriter();
await using var rssWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings {
Async = true
await using var stream = new MemoryStream();
await using var rssWriter = XmlWriter.Create(stream, new XmlWriterSettings {
Async = true, Encoding = selectedEncoding
});
System.ServiceModel.Syndication.SyndicationFeedFormatter formatter;
if (context.ContentType.Value?.StartsWith("application/rss+xml") is true) {
@ -41,6 +42,6 @@ protected override bool CanWriteType(Type? type)
formatter.WriteTo(rssWriter);
rssWriter.Close();
await httpContext.Response.WriteAsync(stringWriter.ToString(), selectedEncoding);
await httpContext.Response.BodyWriter.WriteAsync(stream.ToArray());
}
}