mirror of https://github.com/Jackett/Jackett
core: fix errors removing old cookies (#13425)
This commit is contained in:
parent
9819f0d968
commit
ab05f1b4e2
|
@ -5,14 +5,11 @@ using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using NLog;
|
|
||||||
|
|
||||||
namespace Jackett.Common.Utils
|
namespace Jackett.Common.Utils
|
||||||
{
|
{
|
||||||
public static class CookieUtil
|
public static class CookieUtil
|
||||||
{
|
{
|
||||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
|
||||||
// NOTE: we are not checking non-ascii characters and we should
|
// NOTE: we are not checking non-ascii characters and we should
|
||||||
private static readonly Regex _CookieRegex = new Regex(@"([^\(\)<>@,;:\\""/\[\]\?=\{\}\s]+)=([^,;\\""\s]+)");
|
private static readonly Regex _CookieRegex = new Regex(@"([^\(\)<>@,;:\\""/\[\]\?=\{\}\s]+)=([^,;\\""\s]+)");
|
||||||
|
@ -55,17 +52,15 @@ namespace Jackett.Common.Utils
|
||||||
.InvokeMember("m_domainTable", BindingFlags.NonPublic | BindingFlags.GetField |
|
.InvokeMember("m_domainTable", BindingFlags.NonPublic | BindingFlags.GetField |
|
||||||
BindingFlags.Instance, null, cookieJar, new object[] { });
|
BindingFlags.Instance, null, cookieJar, new object[] { });
|
||||||
foreach (var key in table.Keys)
|
foreach (var key in table.Keys)
|
||||||
try
|
{
|
||||||
{
|
var domain = (string)key;
|
||||||
foreach (Cookie cookie in cookieJar.GetCookies(new Uri($"http://{key}")))
|
if (domain.StartsWith("."))
|
||||||
cookie.Expired = true;
|
domain = domain.Substring(1);
|
||||||
foreach (Cookie cookie in cookieJar.GetCookies(new Uri($"https://{key}")))
|
foreach (Cookie cookie in cookieJar.GetCookies(new Uri($"http://{domain}")))
|
||||||
cookie.Expired = true;
|
cookie.Expired = true;
|
||||||
}
|
foreach (Cookie cookie in cookieJar.GetCookies(new Uri($"https://{domain}")))
|
||||||
catch (Exception)
|
cookie.Expired = true;
|
||||||
{
|
}
|
||||||
logger.Warn("Unable to delete the cookies of domain: " + key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue