mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-06-29 10:23:36 +02:00
Fix InvalidOpEx while trying to read HttpResponseContent 2x (#9861)
This commit is contained in:
parent
a5005e3d01
commit
898bb95564
|
@ -49,20 +49,24 @@ namespace Emby.Dlna.PlayTo
|
||||||
|
|
||||||
private async Task<XDocument?> SendRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
private async Task<XDocument?> SendRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
using var response = await _httpClientFactory.CreateClient(NamedClient.Dlna).SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
|
var client = _httpClientFactory.CreateClient(NamedClient.Dlna);
|
||||||
|
using var response = await client.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
await using MemoryStream ms = new MemoryStream();
|
||||||
|
await response.Content.CopyToAsync(ms, cancellationToken).ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return await XDocument.LoadAsync(
|
return await XDocument.LoadAsync(
|
||||||
stream,
|
ms,
|
||||||
LoadOptions.None,
|
LoadOptions.None,
|
||||||
cancellationToken).ConfigureAwait(false);
|
cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (XmlException)
|
catch (XmlException)
|
||||||
{
|
{
|
||||||
// try correcting the Xml response with common errors
|
// try correcting the Xml response with common errors
|
||||||
var xmlString = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
ms.Position = 0;
|
||||||
|
using StreamReader sr = new StreamReader(ms);
|
||||||
|
var xmlString = await sr.ReadToEndAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// find and replace unescaped ampersands (&)
|
// find and replace unescaped ampersands (&)
|
||||||
xmlString = EscapeAmpersandRegex().Replace(xmlString, "&");
|
xmlString = EscapeAmpersandRegex().Replace(xmlString, "&");
|
||||||
|
@ -70,7 +74,7 @@ namespace Emby.Dlna.PlayTo
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// retry reading Xml
|
// retry reading Xml
|
||||||
var xmlReader = new StringReader(xmlString);
|
using var xmlReader = new StringReader(xmlString);
|
||||||
return await XDocument.LoadAsync(
|
return await XDocument.LoadAsync(
|
||||||
xmlReader,
|
xmlReader,
|
||||||
LoadOptions.None,
|
LoadOptions.None,
|
||||||
|
|
Loading…
Reference in a new issue