Skip to content

Commit 86b5b28

Browse files
Added proxy authentication (#25)
Co-authored-by: ilike2burnthing <59480337+ilike2burnthing@users.noreply.github.com>
1 parent 6d9433a commit 86b5b28

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ all websites as if they're not protected with anything.
4343
var handler = new ClearanceHandler("http://localhost:8191/")
4444
{
4545
MaxTimeout = 60000,
46-
ProxyUrl = "http://127.0.0.1:8888"
46+
ProxyUrl = "http://127.0.0.1:8888",
47+
ProxyUsername = "cool_username",
48+
ProxyPassword = "password4"
4749
};
4850

4951
var client = new HttpClient(handler);
@@ -71,3 +73,13 @@ Example: 60000
7173
The ProxyUrl which will be sent to FlareSolverr.
7274

7375
Example: http://127.0.0.1:8888
76+
77+
### ProxyUsername
78+
The ProxyUsername which will be sent to FlareSolverr. (Only if ProxyUrl has been set)
79+
80+
Use this if the proxy you're using requires authentication.
81+
82+
### ProxyPassword
83+
The ProxyPassword which will be sent to FlareSolverr. (Only if ProxyUrl has been set)
84+
85+
Use this if the proxy you're using requires authentication.

src/FlareSolverrSharp/ClearanceHandler.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ public class ClearanceHandler : DelegatingHandler
3434
/// </summary>
3535
public string ProxyUrl = "";
3636

37+
/// <summary>
38+
/// HTTP Proxy Username.
39+
/// </summary>
40+
public string ProxyUsername = null;
41+
42+
/// <summary>
43+
/// HTTP Proxy Password.
44+
/// </summary>
45+
public string ProxyPassword = null;
46+
3747
private HttpClientHandler HttpClientHandler => InnerHandler.GetMostInnerHandler() as HttpClientHandler;
3848

3949
/// <summary>
@@ -73,7 +83,9 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
7383
_flareSolverr = new FlareSolverr(_flareSolverrApiUrl)
7484
{
7585
MaxTimeout = MaxTimeout,
76-
ProxyUrl = ProxyUrl
86+
ProxyUrl = ProxyUrl,
87+
ProxyUsername = ProxyUsername,
88+
ProxyPassword = ProxyPassword
7789
};
7890
}
7991

src/FlareSolverrSharp/Solvers/FlareSolverr.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class FlareSolverr
1818

1919
public int MaxTimeout = 60000;
2020
public string ProxyUrl = "";
21+
public string ProxyUsername = null;
22+
public string ProxyPassword = null;
2123

2224
public FlareSolverr(string flareSolverrApiUrl)
2325
{
@@ -152,7 +154,15 @@ private FlareSolverrRequestProxy GetProxy()
152154
{
153155
proxy = new FlareSolverrRequestProxy
154156
{
155-
Url = ProxyUrl
157+
Url = ProxyUrl,
158+
};
159+
if (!string.IsNullOrWhiteSpace(ProxyUsername)
160+
{
161+
proxy.Username = ProxyUsername;
162+
};
163+
if (!string.IsNullOrWhiteSpace(ProxyPassword))
164+
{
165+
proxy.Password = ProxyPassword;
156166
};
157167
}
158168
return proxy;
@@ -172,7 +182,7 @@ private HttpContent GenerateFlareSolverrRequest(HttpRequestMessage request, stri
172182
{
173183
FlareSolverrRequest req;
174184
if (string.IsNullOrWhiteSpace(sessionId))
175-
sessionId = null;
185+
sessionId = null;
176186

177187
var url = request.RequestUri.ToString();
178188

@@ -223,6 +233,6 @@ private HttpContent GenerateFlareSolverrRequest(HttpRequestMessage request, stri
223233

224234
return GetSolverRequestContent(req);
225235
}
226-
236+
227237
}
228-
}
238+
}

src/FlareSolverrSharp/Types/FlareSolverrRequestProxy.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@ public class FlareSolverrRequestProxy
66
{
77
[JsonProperty("url")]
88
public string Url;
9+
10+
[JsonProperty("username")]
11+
public string Username;
12+
13+
[JsonProperty("password")]
14+
public string Password;
915
}
1016
}

0 commit comments

Comments
 (0)