[Http]: Clear the 'SendChunked' flag when redirecting.
authorMartin Baulig <martin.baulig@xamarin.com>
Thu, 3 Apr 2014 20:43:36 +0000 (16:43 -0400)
committerMartin Baulig <martin.baulig@xamarin.com>
Tue, 8 Apr 2014 06:24:21 +0000 (08:24 +0200)
mcs/class/System/System.Net/HttpWebRequest.cs
mcs/class/System/System.Net/WebConnectionStream.cs

index e21e5ecc4d45cc1f1cfe075f430728856d14611d..5e1c85296322fb533bc4d483ed4f78dc954ff0ef 100644 (file)
@@ -56,6 +56,7 @@ namespace System.Net
                bool allowBuffering = true;
                X509CertificateCollection certificates;
                string connectionGroup;
+               bool haveContentLength;
                long contentLength = -1;
                HttpContinueDelegate continueDelegate;
                CookieContainer cookieContainer;
@@ -277,6 +278,7 @@ namespace System.Net
                                        throw new ArgumentOutOfRangeException ("value", "Content-Length must be >= 0");
                                        
                                contentLength = value;
+                               haveContentLength = true;
                        }
                }
                
@@ -1153,6 +1155,10 @@ namespace System.Net
                        contentLength = -1;
                        //bodyBufferLength = 0;
                        //bodyBuffer = null;
+                       if (sendChunked) {
+                               sendChunked = false;
+                               webHeaders.RemoveInternal ("Transfer-Encoding");
+                       }
                        uriString = webResponse.Headers ["Location"];
 
                        if (uriString == null)
@@ -1187,7 +1193,7 @@ namespace System.Net
                                        if (contentLength > 0)
                                                continue100 = true;
 
-                                       if (gotRequestStream || contentLength > 0)
+                                       if (haveContentLength || gotRequestStream || contentLength > 0)
                                                webHeaders.SetInternal ("Content-Length", contentLength.ToString ());
                                }
                                webHeaders.RemoveInternal ("Transfer-Encoding");
index c1b8084bdeeb6c41dd94344339d101cbb0f9653c..5a34a3d812440a647546ec0c26ff3a876834f376 100644 (file)
@@ -514,6 +514,13 @@ namespace System.Net
                                Buffer.BlockCopy (buffer, offset, newBuffer, head.Length, size);
                                Buffer.BlockCopy (crlf, 0, newBuffer, head.Length + size, crlf.Length);
 
+                               if (allowBuffering) {
+                                       if (writeBuffer == null)
+                                               writeBuffer = new MemoryStream ();
+                                       writeBuffer.Write (buffer, offset, size);
+                                       totalWritten += size;
+                               }
+
                                buffer = newBuffer;
                                offset = 0;
                                size = chunkSize;