Fix message assembly when a request is truncated (#9)

This commit is contained in:
2022-01-22 14:24:54 +01:00
committed by GitHub
parent f8bf08d9ff
commit 3b0dd84f38
2 changed files with 13 additions and 24 deletions
+11 -22
View File
@@ -403,31 +403,20 @@ namespace MTSC.Common.Http
}
this.HeaderByteCount = (int)ms.Position;
if (this.Headers.ContainsHeader(EntityHeaders.ContentLength))
this.Body = ms.ReadRemainingBytes();
if (this.Headers.ContainsHeader(EntityHeaders.ContentLength) is false)
{
var remainingBytes = int.Parse(this.Headers[EntityHeaders.ContentLength]);
if (remainingBytes <= ms.Length - ms.Position)
{
this.Body = ms.ReadRemainingBytes();
}
else
{
return;
}
}
else
{
if (ms.Length - ms.Position > 1)
{
/*
* If the message contains a body, copy it into a different array
* and save it into the HTTP message;
*/
this.Body = ms.ReadRemainingBytes();
}
this.Complete = true;
return;
}
var contentLength = int.Parse(this.Headers[EntityHeaders.ContentLength]);
if (this.Body.Length >= contentLength)
{
this.Complete = true;
}
this.Complete = true;
return;
}
private string GetField(byte[] buffer, ref int index)
+2 -2
View File
@@ -10,8 +10,8 @@
<Authors>Alexandru-Victor Macocian</Authors>
<Product>MTSC</Product>
<Description>Modular TCP Server and Client</Description>
<AssemblyVersion>5.1.1.0</AssemblyVersion>
<FileVersion>5.1.1.0</FileVersion>
<AssemblyVersion>5.1.2.0</AssemblyVersion>
<FileVersion>5.1.2.0</FileVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Platforms>AnyCPU;x64</Platforms>
<PackageProjectUrl>https://github.com/AlexMacocian/MTSC</PackageProjectUrl>