Restsharp: Adding a manual User-Agent get overwritten by the User-Agent of the RestClient

Created on 7 Dec 2015  路  5Comments  路  Source: restsharp/RestSharp

When adding a header like this
restClient.AddHeader("User-Agent","My-User-Agent")
the RestClient will overrule this with the default "RestSharp 1.x.x.x" like is discussed in this issue. Can this be fixed, so that in the future, people will not be weirded out, when they need to set the User-Agent and it doesn't do anything? ;)

feature-request

Most helpful comment

@newnottakenname to set the user-agent, please use RestClient.UserAgent instead:

RestClient.UserAgent = "test_user_agent";

(where RestClient is an instance of RestClient)

All 5 comments

i'll see what can be done to allow the user content to remain and not get overridden.

@newnottakenname to set the user-agent, please use RestClient.UserAgent instead:

RestClient.UserAgent = "test_user_agent";

(where RestClient is an instance of RestClient)

Although I agree that it is best practice to use OOP to set an User-Agent, instead of adding a header, I believe that adding a header should always overrule the user agent or at least give a warning to tell the programmer that the header has no effect on the actual User-Agent. It took me 2 weeks to figure out that nothing was being changed. I would like to prevent future programmers this problem.

To add to this, we have a requirement that the User agent is changed for almost every request made out, we re-use the Restsharp client instance across many threads, so setting the header for the individual request feels like the right way to go here.

Also, if you are blowing away a value I have set, throw an exception stating I can't set the property, rather than silently replacing it.

client.AddDefaultHeader seems working for me, maybe you can switch to this method

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nilsga picture nilsga  路  5Comments

mwinder picture mwinder  路  7Comments

instriker picture instriker  路  7Comments

guevelamax15000 picture guevelamax15000  路  3Comments

AlexanderSchoenfeld picture AlexanderSchoenfeld  路  3Comments