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");
+
+ cookies.Add (cookie);
+ count = cookies.Count;
+ CheckExpiration ();
+
+ }
- if (count + 1 > capacity)
- throw new CookieException ("Capacity exceeded");
+ // Only needs to be called from AddCookie (Cookie) and GetCookies (Uri)
+ void CheckExpiration ()
+ {
+ if (cookies == null)
+ return;
- cookies.Add (cookie);
- count = cookies.Count;
+ 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);
+ }
}
}
return "";
StringBuilder result = new StringBuilder ();
- foreach (Cookie cookie in cookies) {
+ foreach (Cookie cookie in coll) {
result.Append (cookie.ToString ());
result.Append (';');
}
{
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;
}
}
+ if (cookie.Secure && uri.Scheme != "https")
+ continue;
+
coll.Add (cookie);
}