Zeayii.Infrastructure.Net.Http
0.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Zeayii.Infrastructure.Net.Http --version 0.0.3
NuGet\Install-Package Zeayii.Infrastructure.Net.Http -Version 0.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Zeayii.Infrastructure.Net.Http" Version="0.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zeayii.Infrastructure.Net.Http" Version="0.0.3" />
<PackageReference Include="Zeayii.Infrastructure.Net.Http" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zeayii.Infrastructure.Net.Http --version 0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Zeayii.Infrastructure.Net.Http, 0.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Zeayii.Infrastructure.Net.Http@0.0.3
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zeayii.Infrastructure.Net.Http&version=0.0.3
#tool nuget:?package=Zeayii.Infrastructure.Net.Http&version=0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
简体中文 | English
Zeayii Infrastructure.Net.Http
Infrastructure.Net.Http 是 Zeayii Infrastructure.Net 的 HTTP 实现层,基于 HttpClient 提供可复用、可扩展、可观察的网络访问能力。
组织名称:zeayii
模块定位
- 实现层:承载抽象层接口的默认实现。
- 功能:会话租约、代理调度、处理管线、日志输出。
- 扩展点:日志、代理选择器、处理管线构建器均可替换。
关键能力
- 统一入口:
INetClient提供会话租约。 - 代理策略:内置随机、轮询、加权最小负载选择器。
- 处理管线:重定向、请求头注入、访问日志。
- 可观测性:提供控制台日志实现,默认静默输出(可替换)。
- AOT/Trimming 友好:无反射、无动态。
依赖关系
- 依赖
Infrastructure.Net.Abstractions。 - 依赖
Microsoft.Extensions.DependencyInjection.Abstractions(DI 扩展)。
快速开始
1) 注册服务
using Infrastructure.Net.Http.Configuration;
using Infrastructure.Net.Http.Extensions;
using Infrastructure.Net.Http.Logging;
var options = new NetOptions
{
MinimumLogLevel = NetLogLevel.Info,
Proxies = new[] { "http://127.0.0.1:8080" },
MaxRedirects = 8,
RetryBaseDelay = TimeSpan.FromMilliseconds(200),
RetryMaxDelay = TimeSpan.FromSeconds(15),
RetryMaxAttempts = 3,
DefaultTimeout = TimeSpan.FromSeconds(30),
DefaultHeaders = new Dictionary<string, string>
{
["Accept"] = "text/html,application/xhtml+xml",
["Accept-Language"] = "zh-CN,zh;q=0.9"
},
DefaultCookies = Array.Empty<System.Net.Cookie>()
};
services.AddNet(options);
2) 使用租约
using Infrastructure.Net.Abstractions.Http;
public sealed class ExampleService(INetClient netClient)
{
public async Task<string> FetchAsync(CancellationToken ct)
{
await using var lease = await netClient.RentAsync(NetRouteKind.Proxy, ct);
var response = await lease.HttpClient.GetAsync("https://example.com", ct);
return await response.Content.ReadAsStringAsync(ct);
}
}
架构与组件
1) NetClient
- 负责按路由类型租用会话。
- 代理不可用时自动回落直连。
2) NetHttpClientFactory
- 直连/代理
HttpClient缓存。 - 统一管线装配并复用
CookieContainer。
3) HttpHandlerPipelineBuilder
- 默认管线:
Logging → Retry → Redirect → Header → HttpClientHandler。 - 可替换以注入限速、熔断等策略。
4) ProxyRenter + ProxySelector
ProxyRenter负责代理占用与释放。IProxySelector策略:随机、轮询、加权最小负载。
扩展点
替换日志输出(INetLogger)
services.AddSingleton<INetLogger, MyNetLogger>();
替换代理选择器(IProxySelector)
services.AddSingleton<IProxySelector, MyProxySelector>();
自定义处理管线(IHttpHandlerPipelineBuilder)
services.AddSingleton<IHttpHandlerPipelineBuilder, MyPipelineBuilder>();
运维与可观测性建议
- 日志级别:
NetOptions.MinimumLogLevel控制控制台日志输出。 - 代理健康:业务可在
IProxySelector中维护健康度或黑名单。 - 安全合规:避免记录敏感 Header/Cookie。
版本与兼容性
- 目标框架:
net10.0 - 语言版本:C# 14
许可证
本项目遵循仓库根目录 LICENSE。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.1)
- Zeayii.Infrastructure.Net.Abstractions (>= 0.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Zeayii.Infrastructure.Net.Http:
| Package | Downloads |
|---|---|
|
Zeayii.Luma.Engine
Luma crawl runtime engine. |
GitHub repositories
This package is not used by any popular GitHub repositories.