mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
core: fix cookie parsing (part 2) (#8150)
* core: fix cookie parsing (part 2) After fixing cookie storage in #8133 I noticed that I still have a lot of '.json.bak' files in the Jackett configuration folder. After deleting them they were created again in each request. The cause was we were parsing bad the cookies with '=' character in the value. Most Cloudflare cookies include if so we were sending bad cookies and solving the callenge in each request. This PR should increase performance in several ways: we are not solving the challenge again (it takes time), we are not making extra requests and we are not updating the Jackett configuration in each request (both files '.json' and '.json.bak'). Tested with the client HttpWebClient2NetCore only. Please do some tests with the site 1337x.
This commit is contained in:
@@ -129,21 +129,14 @@ namespace Jackett.Common.Utils.Clients
|
||||
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
|
||||
|
||||
var cookies = new CookieContainer();
|
||||
if (!string.IsNullOrEmpty(webRequest.Cookies))
|
||||
if (!string.IsNullOrWhiteSpace(webRequest.Cookies))
|
||||
{
|
||||
var uri = new Uri(webRequest.Url);
|
||||
var cookieUrl = new Uri(uri.Scheme + "://" + uri.Host); // don't include the path, Scheme is needed for mono compatibility
|
||||
foreach (var c in webRequest.Cookies.Split(';'))
|
||||
{
|
||||
try
|
||||
{
|
||||
cookies.SetCookies(cookieUrl, c.Trim());
|
||||
}
|
||||
catch (CookieException ex)
|
||||
{
|
||||
logger.Info("(Non-critical) Problem loading cookie {0}, {1}, {2}", uri, c, ex.Message);
|
||||
}
|
||||
}
|
||||
// don't include the path, Scheme is needed for mono compatibility
|
||||
var requestUri = new Uri(webRequest.Url);
|
||||
var cookieUrl = new Uri(requestUri.Scheme + "://" + requestUri.Host);
|
||||
var cookieDictionary = CookieUtil.CookieHeaderToDictionary(webRequest.Cookies);
|
||||
foreach (var kv in cookieDictionary)
|
||||
cookies.Add(cookieUrl, new Cookie(kv.Key, kv.Value));
|
||||
}
|
||||
|
||||
var userAgent = webRequest.EmulateBrowser.Value ? BrowserUtil.ChromeUserAgent : "Jackett/" + configService.GetVersion();
|
||||
@@ -231,7 +224,7 @@ namespace Jackett.Common.Utils.Clients
|
||||
}
|
||||
|
||||
// some cloudflare clients are using a refresh header
|
||||
// Pull it out manually
|
||||
// Pull it out manually
|
||||
if (response.StatusCode == HttpStatusCode.ServiceUnavailable && response.Headers.Contains("Refresh"))
|
||||
{
|
||||
var refreshHeaders = response.Headers.GetValues("Refresh");
|
||||
|
Reference in New Issue
Block a user