From 10aa3e43a2d68f9c07b5d8802d030c7f50a10911 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 27 Nov 2021 21:46:55 -0600 Subject: [PATCH] Fixed: (Cardigann) Use correct encoding for Auth and Download calls --- .../Http/HttpRequestBuilder.cs | 10 +++++++ .../Cardigann/CardigannRequestGenerator.cs | 30 +++++++++++++------ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/NzbDrone.Common/Http/HttpRequestBuilder.cs b/src/NzbDrone.Common/Http/HttpRequestBuilder.cs index 249a403e9..644d73908 100644 --- a/src/NzbDrone.Common/Http/HttpRequestBuilder.cs +++ b/src/NzbDrone.Common/Http/HttpRequestBuilder.cs @@ -14,6 +14,7 @@ namespace NzbDrone.Common.Http public HttpAccept HttpAccept { get; set; } public HttpUri BaseUrl { get; private set; } public string ResourceUrl { get; set; } + public Encoding Encoding { get; set; } public List> QueryParams { get; private set; } public List> SuffixQueryParams { get; private set; } public Dictionary Segments { get; private set; } @@ -37,6 +38,7 @@ namespace NzbDrone.Common.Http BaseUrl = new HttpUri(baseUrl); ResourceUrl = string.Empty; Method = HttpMethod.GET; + Encoding = Encoding.UTF8; QueryParams = new List>(); SuffixQueryParams = new List>(); Segments = new Dictionary(); @@ -101,6 +103,7 @@ namespace NzbDrone.Common.Http protected virtual void Apply(HttpRequest request) { request.Method = Method; + request.Encoding = Encoding; request.SuppressHttpError = SuppressHttpError; request.UseSimplifiedUserAgent = UseSimplifiedUserAgent; request.AllowAutoRedirect = AllowAutoRedirect; @@ -301,6 +304,13 @@ namespace NzbDrone.Common.Http return this; } + public virtual HttpRequestBuilder SetEncoding(Encoding encoding) + { + Encoding = encoding; + + return this; + } + public virtual HttpRequestBuilder AddPrefixQueryParam(string key, object value, bool replace = false) { if (replace) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannRequestGenerator.cs index 052407c92..5c1d631b4 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannRequestGenerator.cs @@ -187,6 +187,7 @@ namespace NzbDrone.Core.Indexers.Cardigann Method = HttpMethod.POST, AllowAutoRedirect = true, SuppressHttpError = true, + Encoding = _encoding }; foreach (var pair in pairs) @@ -328,7 +329,8 @@ namespace NzbDrone.Core.Indexers.Cardigann var requestBuilder = new HttpRequestBuilder(captchaUrl.ToString()) { LogResponseContent = true, - Method = HttpMethod.GET + Method = HttpMethod.GET, + Encoding = _encoding }; requestBuilder.Headers.Add("Referer", loginUrl); @@ -393,7 +395,8 @@ namespace NzbDrone.Core.Indexers.Cardigann { LogResponseContent = true, Method = HttpMethod.POST, - AllowAutoRedirect = true + AllowAutoRedirect = true, + Encoding = _encoding }; requestBuilder.Headers.Add("Referer", SiteLink); @@ -422,7 +425,8 @@ namespace NzbDrone.Core.Indexers.Cardigann LogResponseContent = true, Method = HttpMethod.POST, AllowAutoRedirect = true, - SuppressHttpError = true + SuppressHttpError = true, + Encoding = _encoding }; requestBuilder.SetCookies(Cookies); @@ -463,7 +467,8 @@ namespace NzbDrone.Core.Indexers.Cardigann { LogResponseContent = true, Method = HttpMethod.GET, - SuppressHttpError = true + SuppressHttpError = true, + Encoding = _encoding }; requestBuilder.Headers.Add("Referer", SiteLink); @@ -487,7 +492,8 @@ namespace NzbDrone.Core.Indexers.Cardigann { LogResponseContent = true, Method = HttpMethod.GET, - SuppressHttpError = true + SuppressHttpError = true, + Encoding = _encoding }; requestBuilder.Headers.Add("Referer", SiteLink); @@ -559,7 +565,8 @@ namespace NzbDrone.Core.Indexers.Cardigann var requestBuilder = new HttpRequestBuilder(loginUrl.AbsoluteUri) { LogResponseContent = true, - Method = HttpMethod.GET + Method = HttpMethod.GET, + Encoding = _encoding }; requestBuilder.Headers.Add("Referer", SiteLink); @@ -613,6 +620,7 @@ namespace NzbDrone.Core.Indexers.Cardigann var request = new HttpRequestBuilder(captchaUrl.ToString()) .SetCookies(landingResult.GetCookies()) .SetHeader("Referer", loginUrl.AbsoluteUri) + .SetEncoding(_encoding) .Build(); var response = await HttpClient.ExecuteProxiedAsync(request, Definition); @@ -693,6 +701,7 @@ namespace NzbDrone.Core.Indexers.Cardigann var httpRequest = new HttpRequestBuilder(requestLinkStr) .SetCookies(Cookies ?? new Dictionary()) + .SetEncoding(_encoding) .SetHeader("Referer", referer); httpRequest.Method = method; @@ -731,6 +740,7 @@ namespace NzbDrone.Core.Indexers.Cardigann var request = new HttpRequestBuilder(link.ToString()) .SetCookies(Cookies ?? new Dictionary()) .SetHeaders(headers ?? new Dictionary()) + .SetEncoding(_encoding) .Build(); request.AllowAutoRedirect = true; @@ -779,6 +789,7 @@ namespace NzbDrone.Core.Indexers.Cardigann var hashDownloadRequest = new HttpRequestBuilder(torrentLink.AbsoluteUri) .SetCookies(Cookies ?? new Dictionary()) .SetHeaders(headers ?? new Dictionary()) + .SetEncoding(_encoding) .Build(); hashDownloadRequest.Method = method; @@ -819,6 +830,7 @@ namespace NzbDrone.Core.Indexers.Cardigann var testLinkRequest = new HttpRequestBuilder(torrentLink.ToString()) .SetCookies(Cookies ?? new Dictionary()) .SetHeaders(headers ?? new Dictionary()) + .SetEncoding(_encoding) .Build(); response = await HttpClient.ExecuteProxiedAsync(testLinkRequest, Definition); @@ -837,6 +849,7 @@ namespace NzbDrone.Core.Indexers.Cardigann var selectorDownloadRequest = new HttpRequestBuilder(link.AbsoluteUri) .SetCookies(Cookies ?? new Dictionary()) .SetHeaders(headers ?? new Dictionary()) + .SetEncoding(_encoding) .Build(); selectorDownloadRequest.Method = method; @@ -856,6 +869,7 @@ namespace NzbDrone.Core.Indexers.Cardigann var downloadRequest = new HttpRequestBuilder(link.AbsoluteUri) .SetCookies(Cookies ?? new Dictionary()) .SetHeaders(headers ?? new Dictionary()) + .SetEncoding(_encoding) .Build(); downloadRequest.Method = method; @@ -1080,9 +1094,7 @@ namespace NzbDrone.Core.Indexers.Cardigann requestbuilder.SetHeaders(headers ?? new Dictionary()); } - var request = new CardigannRequest(requestbuilder.Build(), variables, searchPath); - - request.HttpRequest.Encoding = Encoding.GetEncoding(_definition.Encoding); + var request = new CardigannRequest(requestbuilder.SetEncoding(_encoding).Build(), variables, searchPath); yield return request; }