Closed shagilt closed 5 years ago
TL;DR
Will Polly use same request in each retry?
Yes
A Polly retry policy in a delegating handler created by HttpClientFactory does not create a new HttpRequestMessage
; it just retries using the HttpRequestMessage
which has been passed to it. The lifetime/scope of HttpRequestMessage
is controlled by whatever created it - HttpClient
, or your code if you create the HttpRequestMessage
and pass it into an overload on HttpClient
which takes HttpRequestMessage
as an input parameter.
To understand how HttpClientFactory uses the policy in a delegating handler, here you can see the latest source code of the DelegatingHandler which HttpClientFactory creates, to wrap the Polly policy.
The extension overload you quote
public static IHttpClientBuilder AddPolicyHandler(this IHttpClientBuilder builder, Func<IServiceProvider, HttpRequestMessage, IAsyncPolicy> policySelector);
takes the existing HttpRequestMessage
as an input parameter, and returns (selects or creates) a policy using it.
Thank you @reisenberger
Summary: What are you wanting to achieve? We are adding new handler to add header in the request before sending request. I see when retry happens, I see header is already present from previous retry. Will Polly use same request in each retry?
What code or approach do you have so far?
This is the extension I am using