ResilienceLab.Http 0.5.0

dotnet add package ResilienceLab.Http --version 0.5.0
                    
NuGet\Install-Package ResilienceLab.Http -Version 0.5.0
                    
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="ResilienceLab.Http" Version="0.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ResilienceLab.Http" Version="0.5.0" />
                    
Directory.Packages.props
<PackageReference Include="ResilienceLab.Http" />
                    
Project file
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 ResilienceLab.Http --version 0.5.0
                    
#r "nuget: ResilienceLab.Http, 0.5.0"
                    
#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 ResilienceLab.Http@0.5.0
                    
#: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=ResilienceLab.Http&version=0.5.0
                    
Install as a Cake Addin
#tool nuget:?package=ResilienceLab.Http&version=0.5.0
                    
Install as a Cake Tool

ResilienceLab.Http

Biblioteca educativa propia para .NET 10: reintentos HTTP con espera exponencial acotada, full jitter, Retry-After y cancelación.

using ResilienceLab.Http;

// Reutiliza este HttpClient durante la vida del servicio.
var http = new HttpClient();
var resilient = new ResilientHttpClient(http);
using var response = await resilient.SendAsync(
    () => new HttpRequestMessage(HttpMethod.Get, "https://example.com/api/status"),
    cancellationToken);
var body = await response.Content.ReadAsStringAsync(cancellationToken);

Por defecto hay tres reintentos adicionales (cuatro envíos como máximo), retraso base de 200 ms, máximo de 10 s y jitter. Sólo se reintentan GET y HEAD ante HttpRequestException o respuestas 408, 429, 502, 503 y 504. OperationCanceledException nunca se reintenta, incluido el timeout propio de HttpClient. Una respuesta fallida final se devuelve sin llamar automáticamente a EnsureSuccessStatusCode(); un error de transporte final se propaga.

Para otros métodos, configura AllowRetryForIdempotentOperations = true únicamente cuando tu servicio garantice la idempotencia (por ejemplo, con una clave de idempotencia). La fábrica debe crear una solicitud y un contenido nuevos en cada intento. No reutilices streams consumidos. Los errores de la fábrica no se reintentan. Cada llamada debe representar la misma operación lógica.

Retry-After admite segundos y fecha: se espera el mayor valor entre el backoff y la cabecera, limitado siempre por MaxDelay. Por ello un valor superior al máximo configurado puede producir un reintento anterior al solicitado por el servidor. Una cabecera inválida o una fecha pasada no incrementan la espera.

El wrapper manual no libera el HttpClient. Sí libera cada solicitud y cada respuesta descartada antes de esperar; el consumidor libera la respuesta final. Su RequestMessage, si existe, ya estará liberado; no reutilices su contenido. Se usa ResponseHeadersRead: los reintentos terminan al recibir las cabeceras. La lectura posterior del cuerpo no se reintenta y debe recibir su propio token. Consulta el comportamiento de finalización de HttpClient.SendAsync en Microsoft Learn.

Las pruebas usan un handler simulado y tiempo controlado: no llaman a Internet. El paquete se genera localmente como versión 0.5.0.

Puedes configurar HttpRetryOptions.Telemetry con una instancia de ResilienceLab.ResilienceTelemetry para emitir logs y métricas de reintentos. Consulta la guía de observabilidad.

IHttpClientFactory

using Microsoft.Extensions.DependencyInjection;
builder.Services.AddResilientHttpClient(
    client => client.BaseAddress = new Uri("https://example.com/"),
    provider => new HttpRetryOptions { MaxRetries = 3 });

Inyecta ResilientHttpClient como cliente tipado transitorio. El registro devuelve IHttpClientBuilder para configurar handlers. Al disponer este cliente tipado, se libera su HttpClient; la fábrica conserva la administración del pool de handlers. Evita capturar clientes tipados en un singleton. El adaptador manual conserva la propiedad externa del HttpClient y no lo dispone. Consulta las estrategias adicionales para combinar con fallback, rate limiting, hedging y reintentos por resultados.

Product 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.0 57 10/5/2026