Skip to content

Commit

Permalink
Merge pull request #1060 from azasp/issue/Content-length-mismatch-too…
Browse files Browse the repository at this point in the history
…-many-bytes-written

Fix: Content length mismatch : too many bytes written
  • Loading branch information
andersjonsson committed May 17, 2024
2 parents 5582c83 + ef0d672 commit 49d57b6
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/SoapCore/SoapEndpointMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http.Headers;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Authentication;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Threading.Tasks;
using System.Xml;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
Expand All @@ -26,6 +12,20 @@
using SoapCore.MessageEncoder;
using SoapCore.Meta;
using SoapCore.ServiceModel;
using System;

Check warning on line 15 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;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http.Headers;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Authentication;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Threading.Tasks;
using System.Xml;

namespace SoapCore
{
Expand Down Expand Up @@ -265,7 +265,10 @@ private async Task ProcessMeta(HttpContext httpContext, bool showDocumentation)
await messageEncoder.WriteMessageAsync(responseMessage, httpContext, ms, _options.IndentWsdl);
ms.Position = 0;
var documentation = SoapDefinition.DeserializeFromStream(ms).GenerateDocumentation();

if (httpContext?.Response.ContentLength <= documentation.Length)
{
httpContext.Response.ContentLength = documentation.Length;
}
await httpContext.Response.WriteAsync(documentation);

return;
Expand Down Expand Up @@ -956,7 +959,7 @@ private Message CreateErrorResponseMessage(
private void SetHttpResponse(HttpContext httpContext, Message message)
{
if (!message.Properties.TryGetValue(HttpResponseMessageProperty.Name, out var value)
|| !(value is HttpResponseMessageProperty httpProperty))
|| value is not HttpResponseMessageProperty httpProperty)
{
return;
}
Expand Down

0 comments on commit 49d57b6

Please sign in to comment.