static Cookie Parse (string s)
{
string [] parts = s.Split (';');
Cookie c = new Cookie ();
for (int i = 0; i < parts.Length; i++) {
string key, value;
int sep = parts[i].IndexOf ('=');
if (sep == -1) {
key = parts [i].Trim ();
value = String.Empty;
} else {
key = parts [i].Substring (0, sep).Trim ();
value = parts [i].Substring (sep + 1).Trim ();
}
switch (key.ToLower (CultureInfo.InvariantCulture)) {
case "path":
case "$path":
if (c.Path.Length == 0)
c.Path = value;
break;
case "domain":
case "$domain":
if (c.Domain.Length == 0) {
c.Domain = value;
// here mono.com means "*.mono.com"
c.ExactDomain = false;
}
break;
case "expires":
case "$expires":
if (c.Expires == DateTime.MinValue) {
#if NET_2_0
c.Expires = DateTime.SpecifyKind (DateTime.ParseExact (value,
@"ddd, dd-MMM-yyyy HH:mm:ss G\MT", CultureInfo.InvariantCulture), DateTimeKind.Utc);
#else
c.Expires = DateTime.ParseExact (value, @"ddd, dd-MMM-yyyy HH:mm:ss G\MT",
CultureInfo.InvariantCulture).ToUniversalTime ();
#endif
}
break;
#if NET_2_0
case "httponly":
c.HttpOnly = true;
break;
#endif
case "secure":
c.Secure = true;
break;
default:
if (c.Name.Length == 0) {
c.Name = key;
c.Value = value;
}
break;
}
}
return c;
}