Skip to content

Commit

Permalink
Merge pull request #1101 from EricSteuart/develop
Browse files Browse the repository at this point in the history
Allows for large files to be processed
  • Loading branch information
andersjonsson authored Dec 10, 2024
2 parents 1f8823e + 1ef6c3e commit 1187499
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/SoapCore/MessageEncoder/SoapMessageEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.IO.Pipelines;
using System.Linq;
using System.Net.Http.Headers;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.WebUtilities;

namespace SoapCore.MessageEncoder
{
Expand Down Expand Up @@ -137,9 +136,18 @@ public async Task<Message> ReadMessageAsync(Stream stream, int maxSizeOfHeaders,
throw new ArgumentNullException(nameof(stream));
}

var ms = new MemoryStream();
await stream.CopyToAsync(ms);
ms.Seek(0, SeekOrigin.Begin);
Stream ms;
if (stream is FileBufferingReadStream)
{
ms = stream;
}
else
{
ms = new MemoryStream();
await stream.CopyToAsync(ms);
ms.Seek(0, SeekOrigin.Begin);
}

XmlReader reader;

var readEncoding = SoapMessageEncoderDefaults.ContentTypeToEncoding(contentType);
Expand Down
6 changes: 6 additions & 0 deletions src/SoapCore/SoapEndpointMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,15 @@ private async Task<Message> ReadMessageAsync(HttpContext httpContext, SoapMessag
}
}
}

#if !NETCOREAPP3_0_OR_GREATER
return await messageEncoder.ReadMessageAsync(httpContext.Request.Body, messageEncoder.MaxSoapHeaderSize, httpContext.Request.ContentType);
#else
if (httpContext.Request.Body is FileBufferingReadStream)
{
return await messageEncoder.ReadMessageAsync(httpContext.Request.Body, messageEncoder.MaxSoapHeaderSize, httpContext.Request.ContentType);
}

return await messageEncoder.ReadMessageAsync(httpContext.Request.BodyReader, messageEncoder.MaxSoapHeaderSize, httpContext.Request.ContentType);
#endif
}
Expand Down

0 comments on commit 1187499

Please sign in to comment.