Skip to content

.NET Core Proxy library based on HttpClient works with FreeProxyList.net

License

Notifications You must be signed in to change notification settings

msigut/FreeProxySharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FreeProxySharp

HttpClient (IHttpClientFactory) + Proxy implementation with Dependency injection support and https://free-proxy-list.net/ as proxy-list source for .NET Standard 2.0 (netstandard2.0).

Library Checks:

For proxy Parse & Check use (test: BasicTest.cs):

// get proxy list
var proxies = await FreeProxyListNet.Parse();
// check all proxies
var checkedProxies = await FreeProxyListNet.Check(proxies, codeFilter: new[] { "DE", "PL" },
	required: 1, maxMiliseconds: 1200);

Or use it all together by Dependency injection init procedure (example at: TestFixture.cs).

// parse & check proxies ; save it into configuration
Options.CheckAndAssignToConfig(codeFilter: new[] { "SE", "DE", "ES", "PL" }, required: 2);

// proxy client, with all proxies gets by CheckAndAssignToConfig
services.AddHttpClientProxy("PROXY", Options);

And then use build-in client HttpProxyClient.cs (test: BasicTest.cs)

var factory = _test.Services.GetRequiredService<HttpProxyFactory>();
var client = factory.GetClientProxy("PROXY");
var html = await client.GetStringSafeAsync("https://httpstat.us");

For common work with IHttpClientFactory clients, configure it by Dependency injection init procedure (example at: TestFixture.cs).

// common client, with all settings from Configuration
services.AddHttpClient("COMMON", Options);
// common client, with retry = 5
services.AddHttpClient("5RETRY", retry: 5);
// common client, with configured for retry when 404 status found (example)
services.AddHttpClient("404TEST", Options, whenRetry: res => res.StatusCode == HttpStatusCode.NotFound);

Configuration example TestOptions.cs:

public class TestOptions : IHttpProxyConfiguration
{
	public int Retry => 2;
        public int RetryFirstDelay => 1;
        public bool GzipEnabled => true;
        public string UserAgent => HttpExtensions.DEFAULT_AGENT;
	
        public IHttpProxyServer[] Proxies { get; set; }
}

Update notice

For update from version 1.0.x -> 1.1.x:

  • ADD: AddHttpClient and AddHttpClientProxy parameter whenRetry for HttpClient retry settings
  • ADD: CheckAndAssignToConfig switch: throwWhenLessThanRequired for exc. when less than requied proxy found
  • ADD: CheckAndAssignToConfig parameter: Timeout for timeout for checking all proxies
  • DEL: IHttpProxyConfiguration.ProxyEnabled removed (use AddHttpClient of AddHttpClientProxy instead manually)
  • DEL: HttpProxyClient removed ; now use HttpExtensions (for common configuration and tasks) & HttpProxyFactory (for work with proxy)

About

.NET Core Proxy library based on HttpClient works with FreeProxyList.net

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published