Author: gonzalo
Date: 2006-08-03 09:44:57 -0400 (Thu, 03 Aug 2006)
New Revision: 63290

Modified:
   trunk/mcs/class/System/System.Net/ChangeLog
   trunk/mcs/class/System/System.Net/CookieCollection.cs
   trunk/mcs/class/System/System.Net/CookieContainer.cs
Log:
2006-08-03 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>

        * CookieCollection.cs:
        * CookieContainer.cs: remove expired cookies.



Modified: trunk/mcs/class/System/System.Net/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Net/ChangeLog 2006-08-03 13:14:53 UTC (rev 
63289)
+++ trunk/mcs/class/System/System.Net/ChangeLog 2006-08-03 13:44:57 UTC (rev 
63290)
@@ -1,3 +1,8 @@
+2006-08-03 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+       * CookieCollection.cs:
+       * CookieContainer.cs: remove expired cookies.
+
 2006-07-07  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * Dns.cs : (GetHostEntry) when passed IP addresses, it does not issue

Modified: trunk/mcs/class/System/System.Net/CookieCollection.cs
===================================================================
--- trunk/mcs/class/System/System.Net/CookieCollection.cs       2006-08-03 
13:14:53 UTC (rev 63289)
+++ trunk/mcs/class/System/System.Net/CookieCollection.cs       2006-08-03 
13:44:57 UTC (rev 63290)
@@ -41,6 +41,9 @@
        {
                ArrayList list = new ArrayList (4);
 
+               internal ArrayList List {
+                       get { return list; }
+               }
                // ICollection
                public int Count {
                        get { return list.Count; }
@@ -133,7 +136,7 @@
                public Cookie this [string name] {
                        get {
                                foreach (Cookie c in list) {
-                                       if (0 == String.Compare (c.Name, name, 
true))
+                                       if (0 == String.Compare (c.Name, name, 
true, CultureInfo.InvariantCulture))
                                                return c;
                                }
                                return null;

Modified: trunk/mcs/class/System/System.Net/CookieContainer.cs
===================================================================
--- trunk/mcs/class/System/System.Net/CookieContainer.cs        2006-08-03 
13:14:53 UTC (rev 63289)
+++ trunk/mcs/class/System/System.Net/CookieContainer.cs        2006-08-03 
13:44:57 UTC (rev 63290)
@@ -132,16 +132,41 @@
 
                void AddCookie (Cookie cookie)
                {
-                       lock (this) {
-                               if (cookies == null)
-                                       cookies = new CookieCollection ();
+                       if (cookies == null)
+                               cookies = new CookieCollection ();
 
-                               if (count + 1 > capacity)
-                                       throw new CookieException ("Capacity 
exceeded");
+                       if (count + 1 > capacity)
+                               throw new CookieException ("Capacity exceeded");
 
-                               cookies.Add (cookie);
-                               count = cookies.Count;
+                       cookies.Add (cookie);
+                       count = cookies.Count;
+                       CheckExpiration ();
+
+               }
+
+               // Only needs to be called from AddCookie (Cookie) and 
GetCookies (Uri)
+               void CheckExpiration ()
+               {
+                       if (cookies == null)
+                               return;
+
+                       ArrayList removed = null;
+                       for (int i = cookies.Count - 1; i >= 0; i--) {
+                               Cookie cookie = cookies [i];
+                               if (cookie.Expired) {
+                                       if (removed == null)
+                                               removed = new ArrayList ();
+                                       removed.Add (i);
+                               }
                        }
+
+                       if (removed != null) {
+                               // We went backwards above, so this works.
+                               ArrayList list = cookies.List;
+                               foreach (int n in removed) {
+                                       list.RemoveAt (n);
+                               }
+                       }
                }
 
                public void Add (CookieCollection cookies)
@@ -244,11 +269,12 @@
                {
                        if (uri == null)
                                throw new ArgumentNullException ("uri");
-                       
+
+                       CheckExpiration ();
                        CookieCollection coll = new CookieCollection ();
                        if (cookies == null)
                                return coll;
-                       
+
                        foreach (Cookie cookie in cookies) {
                                string domain = cookie.Domain;
                                string host = uri.Host;
@@ -273,7 +299,7 @@
                                        }
                                }
 
-                               if (uri.Scheme == "https" && !cookie.Secure)
+                               if (cookie.Secure && uri.Scheme != "https")
                                        continue;
 
                                coll.Add (cookie);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to