If a CookieContainer is set, always use its cookies.
authorMartin Potter <martin.potter@logos.com>
Wed, 1 Aug 2012 14:11:46 +0000 (07:11 -0700)
committerMartin Potter <martin.potter@logos.com>
Mon, 6 Aug 2012 04:52:54 +0000 (21:52 -0700)
Previously, cookies from the WebHeaderCollection and CookieContainer were sent. This also fixes a bug with ServicePoint sending duplicate cookies when SendRequestHeaders is called more than once:

* WebConnection.InitConnection
* HttpWebRequest.SetWriteStream
* HttpWebRequest. SendRequestHeaders
* WebConnectionStream.WriteRequest
* HttpWebRequest.SendRequestHeaders

Replacing the cookie header value in the WebHeaderCollection with the cookies stored in the CookieContainer also matches the behavior of Microsoft's .NET implementation.

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

index dbf1cb3b5f0dd57010a667bbc28e948d5197d598..4bb0684c93bfef1323afddee1fb2a6b053fd18a2 100644 (file)
@@ -1145,7 +1145,9 @@ namespace System.Net
                        if (cookieContainer != null) {
                                string cookieHeader = cookieContainer.GetCookieHeader (actualUri);
                                if (cookieHeader != "")
-                                       webHeaders.SetInternal ("Cookie", cookieHeader);
+                                       webHeaders.RemoveAndAdd ("Cookie", cookieHeader);
+                               else
+                                       webHeaders.RemoveInternal ("Cookie");
                        }
 
                        string accept_encoding = null;