From cf776b920f64f2ac0db2cc1fb5d38207c1175e16 Mon Sep 17 00:00:00 2001 From: FFace32 Date: Tue, 10 Oct 2023 14:38:36 +0300 Subject: [PATCH 1/4] Added proxy authentication --- README.md | 14 +++++++++++++- src/FlareSolverrSharp/ClearanceHandler.cs | 14 +++++++++++++- src/FlareSolverrSharp/Solvers/FlareSolverr.cs | 8 ++++++-- .../Types/FlareSolverrRequestProxy.cs | 11 ++++++++++- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 920a1ff..b26c5a4 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,9 @@ all websites as if they're not protected with anything. var handler = new ClearanceHandler("http://localhost:8191/") { MaxTimeout = 60000, - ProxyUrl = "http://127.0.0.1:8888" + ProxyUrl = "http://127.0.0.1:8888", + ProxyUsername = "cool_username", + ProxyPassword = "password4" }; var client = new HttpClient(handler); @@ -71,3 +73,13 @@ Example: 60000 The ProxyUrl which will be sent to FlareSolverr. Example: http://127.0.0.1:8888 + +### ProxyUsername +The ProxyUsername which will be sent to FlareSolverr. (Only if ProxyUrl has been set) + +Use this if the proxy you're using requires authentication. + +### ProxyPassword +The ProxyPassword which will be sent to FlareSolverr. (Only if ProxyUrl has been set) + +Use this if the proxy you're using requires authentication. diff --git a/src/FlareSolverrSharp/ClearanceHandler.cs b/src/FlareSolverrSharp/ClearanceHandler.cs index e166383..2a99fc0 100644 --- a/src/FlareSolverrSharp/ClearanceHandler.cs +++ b/src/FlareSolverrSharp/ClearanceHandler.cs @@ -34,6 +34,16 @@ public class ClearanceHandler : DelegatingHandler /// public string ProxyUrl = ""; + /// + /// HTTP Proxy Username. + /// + public string ProxyUsername = ""; + + /// + /// HTTP Proxy Password. + /// + public string ProxyPassword = ""; + private HttpClientHandler HttpClientHandler => InnerHandler.GetMostInnerHandler() as HttpClientHandler; /// @@ -73,7 +83,9 @@ protected override async Task SendAsync(HttpRequestMessage _flareSolverr = new FlareSolverr(_flareSolverrApiUrl) { MaxTimeout = MaxTimeout, - ProxyUrl = ProxyUrl + ProxyUrl = ProxyUrl, + ProxyUsername = ProxyUsername, + ProxyPassword = ProxyPassword }; } diff --git a/src/FlareSolverrSharp/Solvers/FlareSolverr.cs b/src/FlareSolverrSharp/Solvers/FlareSolverr.cs index f4e6628..7de7191 100644 --- a/src/FlareSolverrSharp/Solvers/FlareSolverr.cs +++ b/src/FlareSolverrSharp/Solvers/FlareSolverr.cs @@ -18,6 +18,8 @@ public class FlareSolverr public int MaxTimeout = 60000; public string ProxyUrl = ""; + public string ProxyUsername = ""; + public string ProxyPassword = ""; public FlareSolverr(string flareSolverrApiUrl) { @@ -152,7 +154,9 @@ private FlareSolverrRequestProxy GetProxy() { proxy = new FlareSolverrRequestProxy { - Url = ProxyUrl + Url = ProxyUrl, + Username = ProxyUsername, + Password = ProxyPassword }; } return proxy; @@ -225,4 +229,4 @@ private HttpContent GenerateFlareSolverrRequest(HttpRequestMessage request, stri } } -} \ No newline at end of file +} diff --git a/src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs b/src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs index d8e3135..95366ec 100644 --- a/src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs +++ b/src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.ComponentModel; +using Newtonsoft.Json; namespace FlareSolverrSharp.Types { @@ -6,5 +7,13 @@ public class FlareSolverrRequestProxy { [JsonProperty("url")] public string Url; + + [DefaultValue("")] + [JsonProperty("username", DefaultValueHandling = DefaultValueHandling.Ignore)] + public string Username; + + [DefaultValue("")] + [JsonProperty("password", DefaultValueHandling = DefaultValueHandling.Ignore)] + public string Password; } } From 8f52d81910b1fa59e17c82ed116da5772dbfdfbc Mon Sep 17 00:00:00 2001 From: FFace32 Date: Tue, 10 Oct 2023 14:39:04 +0300 Subject: [PATCH 2/4] Formatting FlareSolverr.cs --- src/FlareSolverrSharp/Solvers/FlareSolverr.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FlareSolverrSharp/Solvers/FlareSolverr.cs b/src/FlareSolverrSharp/Solvers/FlareSolverr.cs index 7de7191..31911f1 100644 --- a/src/FlareSolverrSharp/Solvers/FlareSolverr.cs +++ b/src/FlareSolverrSharp/Solvers/FlareSolverr.cs @@ -176,7 +176,7 @@ private HttpContent GenerateFlareSolverrRequest(HttpRequestMessage request, stri { FlareSolverrRequest req; if (string.IsNullOrWhiteSpace(sessionId)) - sessionId = null; + sessionId = null; var url = request.RequestUri.ToString(); @@ -227,6 +227,6 @@ private HttpContent GenerateFlareSolverrRequest(HttpRequestMessage request, stri return GetSolverRequestContent(req); } - + } } From 766114a4d9a30573f9db9ca076404aa6b7f6d94a Mon Sep 17 00:00:00 2001 From: FFace32 Date: Tue, 10 Oct 2023 15:32:44 +0300 Subject: [PATCH 3/4] Taking advantage of NullValueHandling.Ignore --- src/FlareSolverrSharp/ClearanceHandler.cs | 4 ++-- src/FlareSolverrSharp/Solvers/FlareSolverr.cs | 4 ++-- src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs | 9 +++------ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/FlareSolverrSharp/ClearanceHandler.cs b/src/FlareSolverrSharp/ClearanceHandler.cs index 2a99fc0..4db553b 100644 --- a/src/FlareSolverrSharp/ClearanceHandler.cs +++ b/src/FlareSolverrSharp/ClearanceHandler.cs @@ -37,12 +37,12 @@ public class ClearanceHandler : DelegatingHandler /// /// HTTP Proxy Username. /// - public string ProxyUsername = ""; + public string ProxyUsername = null; /// /// HTTP Proxy Password. /// - public string ProxyPassword = ""; + public string ProxyPassword = null; private HttpClientHandler HttpClientHandler => InnerHandler.GetMostInnerHandler() as HttpClientHandler; diff --git a/src/FlareSolverrSharp/Solvers/FlareSolverr.cs b/src/FlareSolverrSharp/Solvers/FlareSolverr.cs index 31911f1..c9d9e1e 100644 --- a/src/FlareSolverrSharp/Solvers/FlareSolverr.cs +++ b/src/FlareSolverrSharp/Solvers/FlareSolverr.cs @@ -18,8 +18,8 @@ public class FlareSolverr public int MaxTimeout = 60000; public string ProxyUrl = ""; - public string ProxyUsername = ""; - public string ProxyPassword = ""; + public string ProxyUsername = null; + public string ProxyPassword = null; public FlareSolverr(string flareSolverrApiUrl) { diff --git a/src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs b/src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs index 95366ec..9186e09 100644 --- a/src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs +++ b/src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs @@ -1,5 +1,4 @@ -using System.ComponentModel; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace FlareSolverrSharp.Types { @@ -8,12 +7,10 @@ public class FlareSolverrRequestProxy [JsonProperty("url")] public string Url; - [DefaultValue("")] - [JsonProperty("username", DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonProperty("username")] public string Username; - [DefaultValue("")] - [JsonProperty("password", DefaultValueHandling = DefaultValueHandling.Ignore)] + [JsonProperty("password")] public string Password; } } From e431362bb4c4526f43cfda3dcbde9f5d49bdffc7 Mon Sep 17 00:00:00 2001 From: ilike2burnthing <59480337+ilike2burnthing@users.noreply.github.com> Date: Fri, 1 Mar 2024 03:48:57 +0000 Subject: [PATCH 4/4] Don't use username or password if empty --- src/FlareSolverrSharp/Solvers/FlareSolverr.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/FlareSolverrSharp/Solvers/FlareSolverr.cs b/src/FlareSolverrSharp/Solvers/FlareSolverr.cs index c9d9e1e..866c9e4 100644 --- a/src/FlareSolverrSharp/Solvers/FlareSolverr.cs +++ b/src/FlareSolverrSharp/Solvers/FlareSolverr.cs @@ -155,8 +155,14 @@ private FlareSolverrRequestProxy GetProxy() proxy = new FlareSolverrRequestProxy { Url = ProxyUrl, - Username = ProxyUsername, - Password = ProxyPassword + }; + if (!string.IsNullOrWhiteSpace(ProxyUsername) + { + proxy.Username = ProxyUsername; + }; + if (!string.IsNullOrWhiteSpace(ProxyPassword)) + { + proxy.Password = ProxyPassword; }; } return proxy;