aboutsummaryrefslogtreecommitdiff
path: root/SocketHttpListener/Net/HttpRequestStream.Managed.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2017-07-01 12:24:26 -0400
committerGitHub <noreply@github.com>2017-07-01 12:24:26 -0400
commitff3713153ad2317e1c196f33ac2cba61b449a00e (patch)
tree84d2e6ed5bcb556a2395603b6403c8e992535e6b /SocketHttpListener/Net/HttpRequestStream.Managed.cs
parentfad71a6c7d12c8b207cdf473c7dd7daafa53c174 (diff)
parent2dcad6b5977f5c5be81b18c42506ed8ad3fb73b6 (diff)
Merge pull request #2739 from MediaBrowser/beta
Beta
Diffstat (limited to 'SocketHttpListener/Net/HttpRequestStream.Managed.cs')
-rw-r--r--SocketHttpListener/Net/HttpRequestStream.Managed.cs29
1 files changed, 24 insertions, 5 deletions
diff --git a/SocketHttpListener/Net/HttpRequestStream.Managed.cs b/SocketHttpListener/Net/HttpRequestStream.Managed.cs
index cb02a4d5a..92f4bbb02 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);
@@ -151,7 +166,6 @@ namespace SocketHttpListener.Net
throw new ArgumentNullException(nameof(asyncResult));
var r = asyncResult as HttpStreamAsyncResult;
-
if (r != null)
{
if (!ReferenceEquals(this, r._parent))
@@ -160,7 +174,7 @@ namespace SocketHttpListener.Net
}
if (r._endCalled)
{
- throw new InvalidOperationException("Invalid end call");
+ throw new InvalidOperationException("invalid end call");
}
r._endCalled = true;
@@ -185,8 +199,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;
}