Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

Commit

Permalink
2005-01-19 Gonzalo Paniagua Javier <gonzalo@ximian.com>
Browse files Browse the repository at this point in the history
	* server/XSPWorkerRequest.cs: when Content-Length is set only allow
	sending that amount of bytes in the body. Fixes bug #71092.


svn path=/trunk/xsp/; revision=39193
  • Loading branch information
gonzalop committed Jan 19, 2005
1 parent 04ad091 commit 9441d58
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
2005-01-19 Gonzalo Paniagua Javier <gonzalo@ximian.com>

* server/XSPWorkerRequest.cs: when Content-Length is set only allow
sending that amount of bytes in the body. Fixes bug #71092.

2005-01-13 Raja R Harinath <rharinath@novell.com>

* server/MonoWorkerRequest.cs: Update to compile with the stricter
Expand Down
22 changes: 20 additions & 2 deletions server/XSPWorkerRequest.cs
Expand Up @@ -68,6 +68,8 @@ public class XSPWorkerRequest : MonoWorkerRequest
XSPRequestBroker requestBroker;
bool keepAlive;
bool haveContentLength;
long contentSent;
long contentLength;
bool isclosed;

static string serverHeader;
Expand Down Expand Up @@ -297,6 +299,18 @@ void AddConnectionHeader ()
responseHeaders.Append ("Connection: Keep-Alive\r\n");
}

int UpdateBodyLength (int currentBlockLength)
{
if (!haveContentLength || contentSent < contentLength - currentBlockLength) {
contentSent += currentBlockLength;
return currentBlockLength;
}

int result = (int) (contentLength - contentSent);
contentSent = contentLength;
return result;
}

public override void FlushResponse (bool finalFlush)
{
if (requestBroker == null)
Expand All @@ -318,6 +332,7 @@ public override void FlushResponse (bool finalFlush)
if (oldLength == 0 || oldLength >= 32768) {
requestBroker.Write (requestId, headerBytes, 0, headerBytes.Length);
} else {
oldLength = UpdateBodyLength (oldLength);
// Attempt not to send a minimum of 2 packets
int newLength = oldLength + headerBytes.Length;
response.SetLength (newLength);
Expand All @@ -333,7 +348,8 @@ public override void FlushResponse (bool finalFlush)

if (response.Length != 0) {
byte [] bytes = response.GetBuffer ();
requestBroker.Write (requestId, bytes, 0, (int) response.Length);
int len = UpdateBodyLength ((int) response.Length);
requestBroker.Write (requestId, bytes, 0, len);
}

if (finalFlush)
Expand Down Expand Up @@ -625,8 +641,10 @@ public override void SendUnknownResponseHeader (string name, string value)
}

if (!sentConnection && !haveContentLength &&
String.Compare (name, "Content-Length", true, CultureInfo.InvariantCulture) == 0)
String.Compare (name, "Content-Length", true, CultureInfo.InvariantCulture) == 0) {
haveContentLength = true;
contentLength = Int64.Parse (value); // This should work, otherwise HttpResponse throws.
}

if (!headersSent) {
responseHeaders.Append (name);
Expand Down

0 comments on commit 9441d58

Please sign in to comment.