From ccb5b14d772c2d1028fa9003ee64fde3cd4196b3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 15 Jun 2017 13:22:05 -0400 Subject: update series resolver --- .../Net/HttpRequestStream.Managed.cs | 32 +++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'SocketHttpListener/Net/HttpRequestStream.Managed.cs') diff --git a/SocketHttpListener/Net/HttpRequestStream.Managed.cs b/SocketHttpListener/Net/HttpRequestStream.Managed.cs index cb02a4d5a..2b5dfc838 100644 --- a/SocketHttpListener/Net/HttpRequestStream.Managed.cs +++ b/SocketHttpListener/Net/HttpRequestStream.Managed.cs @@ -104,9 +104,24 @@ namespace SocketHttpListener.Net return nread; } + if (_remainingBody > 0) + { + size = (int)Math.Min(_remainingBody, (long)size); + } + nread = _stream.Read(buffer, offset, size); - if (nread > 0 && _remainingBody > 0) + + if (_remainingBody > 0) + { + if (nread == 0) + { + throw new Exception("Bad request"); + } + + //Debug.Assert(nread <= _remainingBody); _remainingBody -= nread; + } + return nread; } @@ -139,7 +154,7 @@ namespace SocketHttpListener.Net // for HTTP pipelining if (_remainingBody >= 0 && size > _remainingBody) { - size = (int)Math.Min(int.MaxValue, _remainingBody); + size = (int)Math.Min(_remainingBody, (long)size); } return _stream.BeginRead(buffer, offset, size, cback, state); @@ -150,9 +165,7 @@ namespace SocketHttpListener.Net if (asyncResult == null) throw new ArgumentNullException(nameof(asyncResult)); - var r = asyncResult as HttpStreamAsyncResult; - - if (r != null) + if (asyncResult is HttpStreamAsyncResult r) { if (!ReferenceEquals(this, r._parent)) { @@ -160,7 +173,7 @@ namespace SocketHttpListener.Net } if (r._endCalled) { - throw new InvalidOperationException("Invalid end call"); + throw new InvalidOperationException("invalid end call"); } r._endCalled = true; @@ -185,8 +198,13 @@ namespace SocketHttpListener.Net throw e.InnerException; } - if (_remainingBody > 0 && nread > 0) + if (_remainingBody > 0) { + if (nread == 0) + { + throw new Exception("Bad request"); + } + _remainingBody -= nread; } -- cgit v1.2.3