RestClientOptions.UserAgent missing from requests with useClientFactory: true
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Start at the RestClient constructor path for useClientFactory: true and inspect ConfigureDefaultParameters when a cached client is reused. Reproduce the two-client example against the same BaseUrl, then verify that UserAgent is present on every outgoing request, including requests from the second instance.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- C#
- Stars
- 9.8k
- Forks
- 2.3k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from restsharp/RestSharp
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 65/100
-
delete 940 Open
Difficulty 1/5 Under an hour Newbie friendliness 35/100
-
js/calculator.js Open
Difficulty 5/5 Over a week Newbie friendliness 10/100
-
index.html Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
-
Difficulty 5/5 Over a week Newbie friendliness 1/100
All issues in restsharp/RestSharp
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:auth FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1788 ·