소스 검색

2006-02-07 Gonzalo Paniagua Javier <[email protected]>

	* HttpWebRequest.cs: don't send the expect-100 if if there's no content.

	* HttpListenerRequest.cs:
	* HttpConnection.cs:
	* RequestStream.cs: use the content length header to avoid reading past
	the end of the stream.

	Patch by Horst Reiterer.


svn path=/trunk/mcs/; revision=56658
Gonzalo Paniagua Javier 20 년 전
부모
커밋
b509cdc267

+ 11 - 0
mcs/class/System/System.Net/ChangeLog

@@ -1,3 +1,14 @@
+2006-02-07 Gonzalo Paniagua Javier <[email protected]>
+
+	* HttpWebRequest.cs: don't send the expect-100 if if there's no content.
+
+	* HttpListenerRequest.cs:
+	* HttpConnection.cs:
+	* RequestStream.cs: use the content length header to avoid reading past
+	the end of the stream.
+
+	Patch by Horst Reiterer.
+
 2006-02-01  Carlos Alberto Cortez <[email protected]>
 
 	* FtpWebRequest.cs: Add supportedCommands array with the sorted

+ 2 - 2
mcs/class/System/System.Net/HttpConnection.cs

@@ -99,7 +99,7 @@ namespace System.Net {
 			stream.BeginRead (buffer, 0, BufferSize, OnRead, this);
 		}
 
-		public RequestStream GetRequestStream (bool chunked)
+		public RequestStream GetRequestStream (bool chunked, long contentlength)
 		{
 			if (i_stream == null) {
 				byte [] buffer = ms.GetBuffer ();
@@ -110,7 +110,7 @@ namespace System.Net {
 					context.Response.SendChunked = true;
 					i_stream = new ChunkedInputStream (context, sock, buffer, position, length);
 				} else {
-					i_stream = new RequestStream (sock, buffer, position, length);
+					i_stream = new RequestStream (sock, buffer, position, length, contentlength);
 				}
 			}
 			return i_stream;

+ 4 - 1
mcs/class/System/System.Net/HttpListenerRequest.cs

@@ -165,7 +165,10 @@ namespace System.Net {
 				return;
 			}
 
-			input_stream = context.Connection.GetRequestStream (is_chunked);
+			if (is_chunked || content_length > 0) {
+				input_stream = context.Connection.GetRequestStream (is_chunked, content_length);
+			}
+
 			if (Headers ["Expect"] == "100-continue") {
 				ResponseStream output = context.Connection.GetResponseStream ();
 				output.InternalWrite (_100continue, 0, _100continue.Length);

+ 2 - 1
mcs/class/System/System.Net/HttpWebRequest.cs

@@ -854,7 +854,8 @@ namespace System.Net
 		{
 			bool continue100 = false;
 			if (contentLength != -1) {
-				continue100 = true;
+				if (contentLength > 0)
+					continue100 = true;
 				webHeaders.SetInternal ("Content-Length", contentLength.ToString ());
 				webHeaders.RemoveInternal ("Transfer-Encoding");
 			} else if (sendChunked) {

+ 32 - 3
mcs/class/System/System.Net/RequestStream.cs

@@ -35,6 +35,7 @@ namespace System.Net {
 		byte [] buffer;
 		int offset;
 		int length;
+		long available;
 		bool disposed;
 
 		internal RequestStream (Socket sock, byte [] buffer, int offset, int length) :
@@ -43,6 +44,16 @@ namespace System.Net {
 			this.buffer = buffer;
 			this.offset = offset;
 			this.length = length;
+			this.available = -1;
+		}
+
+		internal RequestStream (Socket sock, byte [] buffer, int offset, int length, long contentlength) :
+					base (sock, false)
+		{
+			this.buffer = buffer;
+			this.offset = offset;
+			this.length = length;
+			this.available = contentlength;
 		}
 
 		public override bool CanRead {
@@ -106,11 +117,22 @@ namespace System.Net {
 			if (disposed)
 				throw new ObjectDisposedException (typeof (RequestStream).ToString ());
 
+			if (available == 0)
+				return 0;
+
 			int nread = FillFromBuffer (buffer, offset, count);
 			if (nread > 0)
 				return nread;
 
-			return base.Read (buffer, offset, count);
+			// Avoid reading past the end of the request to allow
+			// for HTTP pipelining
+			if (available != -1 && count > available)
+				count = (int) available;
+
+			nread = base.Read (buffer, offset, count);
+			if (available != -1)
+				available -= nread;
+			return nread;
 		}
 
 		public override IAsyncResult BeginRead (byte [] buffer, int offset, int count,
@@ -120,7 +142,7 @@ namespace System.Net {
 				throw new ObjectDisposedException (typeof (RequestStream).ToString ());
 
 			int nread = FillFromBuffer (buffer, offset, count);
-			if (nread > 0) {
+			if (nread > 0 || available == 0) {
 				HttpStreamAsyncResult ares = new HttpStreamAsyncResult ();
 				ares.Buffer = buffer;
 				ares.Offset = offset;
@@ -132,6 +154,10 @@ namespace System.Net {
 				return ares;
 			}
 
+			// Avoid reading past the end of the request to allow
+			// for HTTP pipelining
+			if (available != -1 && count > available)
+				count = (int) Math.Min (Int32.MaxValue, available);
 			return base.BeginRead (buffer, offset, count, cback, state);
 		}
 
@@ -151,7 +177,10 @@ namespace System.Net {
 			}
 
 			// Close on exception?
-			return base.EndRead (ares);
+			int nread = base.EndRead (ares);
+			if (available != -1)
+				available -= nread;
+			return nread;
 		}
 
 		public override long Seek (long offset, SeekOrigin origin)