1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2024-12-29 11:17:22 +00:00

core: fix cookie storage. resolves #8126 (#8133)

This commit is contained in:
Diego Heras 2020-04-12 15:00:14 +02:00 committed by GitHub
parent 0fc36236cd
commit 8ce15eca73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using AutoMapper;
using Jackett.Common.Models;
@ -349,6 +350,9 @@ namespace Jackett.Common.Indexers
public abstract class BaseWebIndexer : BaseIndexer, IWebIndexer
{
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
private readonly Regex _cookieRegex = new Regex(@"([^\(\)<>@,;:\\""/\[\]\?=\{\}\s]+)=([^,;\\""\s]+)");
protected BaseWebIndexer(string name, string link, string description, IIndexerConfigurationService configService, WebClient client, Logger logger, ConfigurationData configData, IProtectionService p, TorznabCapabilities caps = null, string downloadBase = null)
: base(name, link, description, configService, logger, configData, p)
{
@ -605,17 +609,16 @@ namespace Jackett.Common.Indexers
private string ResolveCookies(string incomingCookies = "")
{
var redirRequestCookies = (CookieHeader != null && CookieHeader != "" ? CookieHeader + " " : "") + incomingCookies;
var expression = new System.Text.RegularExpressions.Regex(@"([^\\,;\s]+)=([^=\\,;\s]*)");
var cookieDIctionary = new Dictionary<string, string>();
var matches = expression.Match(redirRequestCookies);
var redirRequestCookies = string.IsNullOrWhiteSpace(CookieHeader) ? incomingCookies : CookieHeader + " " + incomingCookies;
var cookieDictionary = new Dictionary<string, string>();
var matches = _cookieRegex.Match(redirRequestCookies);
while (matches.Success)
{
if (matches.Groups.Count > 2)
cookieDIctionary[matches.Groups[1].Value] = matches.Groups[2].Value;
cookieDictionary[matches.Groups[1].Value] = matches.Groups[2].Value;
matches = matches.NextMatch();
}
return string.Join("; ", cookieDIctionary
return string.Join("; ", cookieDictionary
.Where(kv => kv.Key != "cf_use_ob" && kv.Key != "cf_ob_info") // These cookies are causing BadGateway errors, so we drop them, see issue #2306
.Select(kv => kv.Key.ToString() + "=" + kv.Value.ToString()).ToArray());
}