aboutsummaryrefslogtreecommitdiff
path: root/SocketHttpListener/Net/HttpRequestStream.Managed.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2017-06-15 13:22:05 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2017-06-15 13:22:05 -0400
commitccb5b14d772c2d1028fa9003ee64fde3cd4196b3 (patch)
tree294a56f3d34ed3e921257ca124f7d2fa28f79d2e /SocketHttpListener/Net/HttpRequestStream.Managed.cs
parentb615a2aeb16a527fe56a88a352574d76e77783e8 (diff)
update series resolver
Diffstat (limited to 'SocketHttpListener/Net/HttpRequestStream.Managed.cs')
-rw-r--r--SocketHttpListener/Net/HttpRequestStream.Managed.cs32
1 files changed, 25 insertions, 7 deletions
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;
}