/// <summary> /// Adds <see cref="UriCookieHeader"/> instances for one or more cookies from an HTTP cookie header to the <see cref="CookieManager"/> for a specific URI. /// </summary> /// <param name="uri">The URI.</param> /// <param name="cookieHeader">The cookie header.</param> public void SetCookies(Uri uri, string cookieHeader) { lock (m_objLock) { // track this URI (we need it to retrieve the cookies later) m_setUris.Add(uri); // store the cookies CookieContainer.SetCookies(uri, cookieHeader); } CookiesChanged?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Expires the cookies, and raising the <see cref="CookiesChanged"/> event if there were any cookies (even potentially already expired ones). /// </summary> public void ExpireCookies() { DateTime expires = DateTime.Now.AddDays(-1); bool empty; lock (m_objLock) { empty = m_setUris.Count == 0; if (!empty) { foreach (var cookie in m_setUris.SelectMany(uri => CookieContainer.GetCookies(uri).Cast <Cookie>())) { cookie.Expires = expires; } } } if (!empty) { CookiesChanged?.Invoke(this, EventArgs.Empty); } }