Hymma.HttpClientFactory
1.0.8
Prefix Reserved
dotnet add package Hymma.HttpClientFactory --version 1.0.8
NuGet\Install-Package Hymma.HttpClientFactory -Version 1.0.8
<PackageReference Include="Hymma.HttpClientFactory" Version="1.0.8" />
<PackageVersion Include="Hymma.HttpClientFactory" Version="1.0.8" />
<PackageReference Include="Hymma.HttpClientFactory" />
paket add Hymma.HttpClientFactory --version 1.0.8
#r "nuget: Hymma.HttpClientFactory, 1.0.8"
#:package Hymma.HttpClientFactory@1.0.8
#addin nuget:?package=Hymma.HttpClientFactory&version=1.0.8
#tool nuget:?package=Hymma.HttpClientFactory&version=1.0.8
HttpClientFactory For netcore And framework
NUGET Install-Package HttpClientFactory
supported netcore2.0 and framework4.5+
Why need HttpClientFactory?
As you know, HttpClient has a trap for using!
- if not Singleton, each instance of HttpClient will open a new socket connection and on high traffic sites you can exhaust the available pool and receive a System.Net.Sockets.SocketException
- if Singleton,HttpClient doesn't respect DNS changes!
So how to use HttpClient correctly?
//useage 1: same Host use same HttpClient
PerHostHttpClientFactory perHostHttpClientFactory = new PerHostHttpClientFactory();// can be static
//or you can change default timeout for perFactory
PerHostHttpClientFactory perHostHttpClientFactory = new PerHostHttpClientFactory(TimeSpan.FromSeconds(10));
HttpClient client = perHostHttpClientFactory.GetHttpClient("http://www.baidu.com");
//useage 2: per url use per HttpClient
PerUrlHttpClientFactory perUrlHttpClientFactory = new PerUrlHttpClientFactory();
//or you can change default timeout for perFactory
PerUrlHttpClientFactory perUrlHttpClientFactory = new PerUrlHttpClientFactory(TimeSpan.FromSeconds(10));
HttpClient client = perUrlHttpClientFactory.GetHttpClient("http://www.baidu.com");
//useage 3: per proxy use per HttpClient
PerHostHttpClientFactory perHostHttpClientFactory = new PerHostHttpClientFactory();
//or you can change default timeout for perFactory
PerHostHttpClientFactory perHostHttpClientFactory = new PerHostHttpClientFactory(TimeSpan.FromSeconds(10));
HttpClient client = perUrlHttpClientFactory.GetProxiedHttpClient("http://127.0.0.1:8080");
Easy to implement
public class XXXHttpClientFactory : HttpClientFactoryBase
{
protected override string GetCacheKey(string key)
{
return key;
}
protected override HttpClient CreateHttpClient(HttpMessageHandler handler)
{
return new HttpClient(handler)
{
Timeout = TimeSpan.FromSeconds(20),
};
}
protected override HttpMessageHandler CreateMessageHandler()
{
var handler = new HttpClientHandler();
handler.Proxy = new WebProxy("xxx");
return handler;
}
}
Remark
- Default Timeout is TimeSpan.FromSeconds(100)
- Default ConnectionLeaseExpired is TimeSpan.FromMinutes(1)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Hymma.HttpClientFactory:
| Package | Downloads |
|---|---|
|
Hymma.Lm.EndUser
End-user SDK for license-management.com platform. Provides license validation, trial management, and activation handling for Windows desktop applications. |
|
|
LicenseManagement.EndUser
End-user SDK for license-management.com platform. Provides license validation, trial management, and activation handling for Windows desktop applications. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Assembly renamed to Hymma.HttpClientFactory.dll for consistency with package name. Strong-name signed.