Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows for large files to be processed #1101

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -13,10 +13,10 @@
using SoapCore.Meta;
using SoapCore.Serializer;
using SoapCore.ServiceModel;
using System;

Check warning on line 16 in src/SoapCore/SoapEndpointMiddleware.cs

View workflow job for this annotation

GitHub Actions / Analyze

Using directive for 'System' should appear before directive for 'SoapCore.ServiceModel' (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1208.md)
using System.Collections.Generic;

Check warning on line 17 in src/SoapCore/SoapEndpointMiddleware.cs

View workflow job for this annotation

GitHub Actions / Analyze

Using directive for 'System.Collections.Generic' should appear before directive for 'SoapCore.ServiceModel' (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1208.md)
using System.Diagnostics;

Check warning on line 18 in src/SoapCore/SoapEndpointMiddleware.cs

View workflow job for this annotation

GitHub Actions / Analyze

Using directive for 'System.Diagnostics' should appear before directive for 'SoapCore.ServiceModel' (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1208.md)
using System.IO;

Check warning on line 19 in src/SoapCore/SoapEndpointMiddleware.cs

View workflow job for this annotation

GitHub Actions / Analyze

Using directive for 'System.IO' should appear before directive for 'SoapCore.ServiceModel' (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1208.md)
using System.Linq;
using System.Net;
using System.Net.Http.Headers;
Expand Down Expand Up @@ -246,9 +246,15 @@
}
}
}

#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
Loading