Skip to content

Commit

Permalink
Fix some proxy-related stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Laiteux committed Oct 20, 2021
1 parent 4cee2d6 commit 7945d6a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Milky/CheckerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public CheckerBuilder WithProxiesFromUrl(string url, ProxySettings settings)
{
var responseString = _lazyWebClient.Value.DownloadString(url);

string[] proxies = responseString.Split(new[] { @"\n", @"\r" }, StringSplitOptions.RemoveEmptyEntries);
string[] proxies = responseString.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

WithProxies(proxies, settings);

Expand Down
14 changes: 7 additions & 7 deletions src/Milky/Models/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public Proxy(string proxy, ProxySettings settings)

internal NetworkCredential Credentials { get; }

internal HttpClient GetHttpClient()
public HttpClient GetHttpClient(CookieContainer cookieContainer = null)
{
var httpMessageHandler = GetHttpMessageHandler();
var httpMessageHandler = GetHttpMessageHandler(cookieContainer);

var httpClient = new HttpClient(httpMessageHandler)
{
Expand All @@ -63,7 +63,7 @@ internal HttpClient GetHttpClient()
return httpClient;
}

private HttpMessageHandler GetHttpMessageHandler()
public HttpMessageHandler GetHttpMessageHandler(CookieContainer cookieContainer = null)
{
if (Settings.Protocol == ProxyProtocol.HTTP)
{
Expand All @@ -72,7 +72,7 @@ private HttpMessageHandler GetHttpMessageHandler()
Proxy = new WebProxy(Host, Port) { Credentials = Credentials },
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = Settings.CookieContainer ?? new CookieContainer()
CookieContainer = cookieContainer ?? new CookieContainer()
};
}

Expand All @@ -92,19 +92,19 @@ private HttpMessageHandler GetHttpMessageHandler()
{
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = Settings.CookieContainer
CookieContainer = cookieContainer
},
ProxyProtocol.SOCKS4A => new ProxyClientHandler<Socks4a>(proxySettings)
{
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = Settings.CookieContainer
CookieContainer = cookieContainer
},
ProxyProtocol.SOCKS5 => new ProxyClientHandler<Socks5>(proxySettings)
{
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = Settings.CookieContainer
CookieContainer = cookieContainer
}
};
}
Expand Down
5 changes: 0 additions & 5 deletions src/Milky/Models/ProxySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,5 @@ public ProxySettings(ProxyProtocol protocol)
/// Whether or not to use/save/keep cookies, usually not recommended for credential stuffing but who knows
/// </summary>
public bool UseCookies { get; set; } = false;

/// <summary>
/// Default <see cref="System.Net.CookieContainer"/>, I see no use case for it for credential stuffing but who knows
/// </summary>
public CookieContainer CookieContainer { get; set; } = null;
}
}

0 comments on commit 7945d6a

Please sign in to comment.