From c2520c86d7ab000d0128dfae2ebb69657b586c76 Mon Sep 17 00:00:00 2001 From: kaso17 Date: Sat, 10 Dec 2016 10:36:42 +0100 Subject: [PATCH] Fix CloudFlare challenges for mono/libcurl --- src/Jackett/Utils/Clients/UnixLibCurlWebClient.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Jackett/Utils/Clients/UnixLibCurlWebClient.cs b/src/Jackett/Utils/Clients/UnixLibCurlWebClient.cs index 4d5eff60c..867d4ac5a 100644 --- a/src/Jackett/Utils/Clients/UnixLibCurlWebClient.cs +++ b/src/Jackett/Utils/Clients/UnixLibCurlWebClient.cs @@ -59,13 +59,14 @@ namespace Jackett.Utils.Clients } } - // Wrapper for Run which takes care of CloudFlare challenges - private async Task RunCloudFlare(WebRequest request) + // Wrapper for Run which takes care of CloudFlare challenges, calls RunCurl + override protected async Task Run(WebRequest request) { - WebClientByteResult result = await Run(request); + WebClientByteResult result = await RunCurl(request); // check if we've received a CloudFlare challenge - if (result.Status == HttpStatusCode.ServiceUnavailable && ((request.Cookies != null && request.Cookies.Contains("__cfduid")) || result.Cookies.Contains("__cfduid"))) + string[] server; + if (result.Status == HttpStatusCode.ServiceUnavailable && result.Headers.TryGetValue("server", out server) && server[0] == "cloudflare-nginx") { logger.Info("UnixLibCurlWebClient: Received a new CloudFlare challenge"); @@ -86,7 +87,7 @@ namespace Jackett.Utils.Clients request.Cookies = response.Cookies + request.Cookies; // re-run the original request with updated cf_clearance cookie - result = await Run(request); + result = await RunCurl(request); // add cf_clearance cookie to the final result so we update the config for the next request result.Cookies = response.Cookies + " " + result.Cookies; @@ -94,7 +95,7 @@ namespace Jackett.Utils.Clients return result; } - override protected async Task Run(WebRequest request) + protected async Task RunCurl(WebRequest request) { Jackett.CurlHelper.CurlResponse response; if (request.Type == RequestType.GET)