/// <summary> /// Initializes a new instance of a <see cref="NapCookie"/> class. /// </summary> /// <param name="requestUri">The request URI that this cookie belongs to.</param> /// <param name="cookieString">The string that will generate a cookie (value of a Set-Cookie header).</param> public NapCookie(Uri requestUri, string cookieString) { var segments = cookieString.Split(';').Select(c => { var split = c.Split('=').Select(s => s?.Trim()).ToList(); if (split.Count > 1) { return(new KeyValuePair <string, string>(split[0], split[1])); } else { return(new KeyValuePair <string, string>(split[0], null)); } }).ToDictionary(kv => kv.Key, kv => kv.Value); if (segments.Count > 0) { Name = segments.First().Key; Value = segments.First().Value; Metadata = new NapCookieMetadata(requestUri, segments.ToDictionary(kv => kv.Key.ToLower(), kv => kv.Value)); } else { Name = null; Value = null; Metadata = new NapCookieMetadata(); } }
/// <summary> /// Initializes a new instance of a <see cref="NapCookie"/> class from a .NET cookie. /// </summary> public NapCookie(Cookie cookie) { Name = cookie.Name; Value = cookie.Value; Metadata = new NapCookieMetadata(cookie); }