2009-06-09 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 9 Jun 2009 15:14:13 +0000 (15:14 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 9 Jun 2009 15:14:13 +0000 (15:14 -0000)
* HttpWebRequest.cs: follow MS docs when throwing
ProtocolViolationException at the beginning of an asynchronous
operation. Fixes bug #465613.

svn path=/trunk/mcs/; revision=135758

mcs/class/System/System.Net/ChangeLog
mcs/class/System/System.Net/HttpWebRequest.cs

index 5d3a6507b9757a9e5c97f94a9e7fda4305137017..89af0e53be9ae2283babce3b6c1d2720c40c55aa 100644 (file)
@@ -1,3 +1,9 @@
+2009-06-09 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * HttpWebRequest.cs: follow MS docs when throwing
+       ProtocolViolationException at the beginning of an asynchronous
+       operation. Fixes bug #465613.
+
 2009-06-08 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * WebConnectionStream.cs: throw a WebException instead of an IOException.
index fa0d2f0fe486701dbf5317b0f108ee49159431c9..f74233ce827198aefc016729ad37dea1d6a55c5a 100644 (file)
@@ -640,19 +640,6 @@ namespace System.Net
                }
 #endif
                
-               void CommonChecks (bool putpost)
-               {
-                       if (method == null)
-                               throw new ProtocolViolationException ("Method is null.");
-
-                       if (putpost && contentLength == -1 && !sendChunked && !allowBuffering)
-                               throw new ProtocolViolationException ("Content-Length not set");
-
-                       string transferEncoding = TransferEncoding;
-                       if (!sendChunked && transferEncoding != null && transferEncoding.Trim () != "")
-                               throw new ProtocolViolationException ("SendChunked should be true.");
-               }
-
                public override IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state) 
                {
                        if (aborted)
@@ -663,7 +650,12 @@ namespace System.Net
                        if (method == null || !send)
                                throw new ProtocolViolationException ("Cannot send data when method is: " + method);
 
-                       CommonChecks (send);
+                       if (contentLength == -1 && !sendChunked && !allowBuffering && KeepAlive)
+                               throw new ProtocolViolationException ("Content-Length not set");
+
+                       string transferEncoding = TransferEncoding;
+                       if (!sendChunked && transferEncoding != null && transferEncoding.Trim () != "")
+                               throw new ProtocolViolationException ("SendChunked should be true.");
                        
                        lock (locker)
                        {
@@ -742,13 +734,17 @@ namespace System.Net
 
                public override IAsyncResult BeginGetResponse (AsyncCallback callback, object state)
                {
+                       if (method == null)
+                               throw new ProtocolViolationException ("Method is null.");
+
                        bool send = (method == "PUT" || method == "POST");
-                       if (send) {
-                               if (ContentLength == -1 && !SendChunked && !AllowWriteStreamBuffering)
-                                       throw new ProtocolViolationException ("Content-Length not set");
-                       }
+                       if (send && contentLength == -1 && !sendChunked && !allowBuffering && KeepAlive)
+                               throw new ProtocolViolationException ("Content-Length not set");
+
+                       string transferEncoding = TransferEncoding;
+                       if (!sendChunked && transferEncoding != null && transferEncoding.Trim () != "")
+                               throw new ProtocolViolationException ("SendChunked should be true.");
 
-                       CommonChecks (send);
                        Monitor.Enter (locker);
                        getResponseCalled = true;
                        if (asyncRead != null && !haveResponse) {