You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the API request fails due to a content length mismatch (specifically header Content-Length > than content), we get the following exception System.Net.Http.HttpRequestException: Error while copying content to a stream., however it is not caught by the resilience pipeline.
My understanding is that the extension method(s) inject a DelegatingHandler to wrap the API request and attempt to detect errors and apply the resilience pipeline accordingly. However, the above exception does not get triggered during the DelegatingHandler unless the content is explicitly read within the handler and therefore the pipeline is never applied.
Reproduction Steps
Client:
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddHttpClient("my-client")
.AddStandardResilienceHandler();
// Use the client
HttpClient client = services.BuildServiceProvider()
.GetRequiredService<IHttpClientFactory>()
.CreateClient("my-client");
// Make resilient HTTP request
HttpResponseMessage response = await client.GetAsync("http://localhost:5174/badlength");
Server:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/badlength", (HttpContext context) =>
{
const string content = "This is the response content";
var incorrectContentLength = content.Length + 10; // Set an incorrect content length
context.Response.Headers["Content-Length"] = incorrectContentLength.ToString();
return content;
});
app.Run();
Expected behavior
The HttpRequestException should be caught and retried given it's declared in the policy to retry the exception type.
Actual behavior
The HttpRequestException is not caught and is thrown to the client program immediately.
Regression?
No response
Known Workarounds
No response
Configuration
.net 8.0 + Windows 11
Other information
No response
The text was updated successfully, but these errors were encountered:
Description
If the API request fails due to a content length mismatch (specifically header Content-Length > than content), we get the following exception
System.Net.Http.HttpRequestException: Error while copying content to a stream.
, however it is not caught by the resilience pipeline.My understanding is that the extension method(s) inject a DelegatingHandler to wrap the API request and attempt to detect errors and apply the resilience pipeline accordingly. However, the above exception does not get triggered during the DelegatingHandler unless the content is explicitly read within the handler and therefore the pipeline is never applied.
Reproduction Steps
Client:
Server:
Expected behavior
The HttpRequestException should be caught and retried given it's declared in the policy to retry the exception type.
Actual behavior
The HttpRequestException is not caught and is thrown to the client program immediately.
Regression?
No response
Known Workarounds
No response
Configuration
.net 8.0 + Windows 11
Other information
No response
The text was updated successfully, but these errors were encountered: