Describe the bug
When useClientFactory: true is passed to the RestClient constructor and UserAgent is set via RestClientOptions.UserAgent, the User-Agent header is missing from outgoing requests for every RestClient instance after the first one sharing the same BaseUrl.
When disabling the client factory the User-Agent is back on every request.
To Reproduce
var options = new RestClientOptions
{
BaseUrl = new Uri("https://httpbin.org"),
UserAgent = "MyApp/1.0"
};
//1st request
var client1 = new RestClient(options, useClientFactory: true);
_ = await client1.GetAsync(new RestRequest("/get"));
// 2nd request
var client2 = new RestClient(options, useClientFactory: true);
_ = await client2.GetAsync(new RestRequest("/get"));
1st raw request from fiddler
GET https://httpbin.org/get HTTP/1.1
Host: httpbin.org
User-Agent: MyApp/1.0
Accept: application/json, text/json, text/x-json, text/javascript, application/xml, text/xml
Accept-Encoding: gzip, deflate, br
2nd raw request from fiddler
GET https://httpbin.org/get HTTP/1.1
Host: httpbin.org
Accept: application/json, text/json, text/x-json, text/javascript, application/xml, text/xml
Accept-Encoding: gzip, deflate, br
Expected behavior
User-Agent should appear on every request regardless of how many RestClient instances are created for the same BaseUrl.
Desktop:
- OS: Windows 10.0.26200.8457
- .NET version: .NET 10.0.8
- Version 114.0.0
Additional context
I suspect that ConfigureDefaultParameters should be called regardless of the client instance coming from cache or not.
Describe the bug
When
useClientFactory: trueis passed to theRestClientconstructor andUserAgentis set viaRestClientOptions.UserAgent, the User-Agent header is missing from outgoing requests for everyRestClientinstance after the first one sharing the sameBaseUrl.When disabling the client factory the User-Agent is back on every request.
To Reproduce
1st raw request from fiddler
2nd raw request from fiddler
Expected behavior
User-Agent should appear on every request regardless of how many RestClient instances are created for the same BaseUrl.
Desktop:
Additional context
I suspect that
ConfigureDefaultParametersshould be called regardless of the client instance coming from cache or not.