42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
namespace ln.http.client
|
|
{
|
|
public class CookieContainer : IEnumerable<HttpCookie>
|
|
{
|
|
public HttpCookie[] Cookies => cookies.ToArray();
|
|
|
|
List<HttpCookie> cookies = new List<HttpCookie>();
|
|
|
|
public CookieContainer()
|
|
{
|
|
}
|
|
|
|
public void Add(HttpCookie httpCookie)
|
|
{
|
|
foreach (HttpCookie cookie in Get(httpCookie.Domain))
|
|
{
|
|
if (cookie.Name.Equals(httpCookie.Name))
|
|
Remove(cookie);
|
|
}
|
|
cookies.Add(httpCookie);
|
|
}
|
|
|
|
public void Remove(HttpCookie httpCookie)
|
|
{
|
|
cookies.Remove(httpCookie);
|
|
}
|
|
|
|
public IEnumerable<HttpCookie> Get(string domain)
|
|
{
|
|
return Cookies.Where((c) => c.Domain.Equals(domain));
|
|
}
|
|
|
|
|
|
public IEnumerator<HttpCookie> GetEnumerator() => cookies.GetEnumerator();
|
|
IEnumerator IEnumerable.GetEnumerator() => cookies.GetEnumerator();
|
|
}
|
|
}
|