public void Add(Cookie cookie) {
if (cookie == null) {
throw new ArgumentNullException("cookie");
}
if (cookie.Domain.Length == 0) {
throw new ArgumentException(SR.GetString(SR.net_emptystringcall), "cookie.Domain");
}
// We don't know cookie verification status -> re-create cookie and verify it
Cookie new_cookie = new Cookie(cookie.Name, cookie.Value);
Uri uri;
new_cookie.Version = cookie.Version;
// We cannot add an invalid cookie into the container.
// Trying to prepare Uri for the cookie verification
string uriStr = (cookie.Secure ? Uri.UriSchemeHttps : Uri.UriSchemeHttp) + Uri.SchemeDelimiter ;
if (cookie.Domain[0] == '.') {
uriStr += "0"; // Uri cctor should eat this, faked host.
new_cookie.Domain = cookie.Domain; // Otherwise keep Domain as implicitly set
}
uriStr += cookie.Domain;
// Either keep Port as implici or set it according to original cookie
if (cookie.PortList != null) {
new_cookie.Port = cookie.Port;
uriStr += ":"+ cookie.PortList[0];
}
// Path must be present, set to root by default
new_cookie.Path = cookie.Path.Length == 0 ? "/" : cookie.Path;
uriStr += cookie.Path;
if(!Uri.TryCreate(uriStr, UriKind.Absolute, out uri))
throw new CookieException(SR.GetString(SR.net_cookie_attribute, "Domain", cookie.Domain));
new_cookie.VerifySetDefaults(CookieVariant.Unknown, uri, IsLocal(uri.Host), m_fqdnMyDomain, true, true);
Add(new_cookie, true);
}