Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a manual User-Agent get overwritten by the User-Agent of the RestClient #787

Closed
mjwsteenbergen opened this issue Dec 7, 2015 · 5 comments

Comments

@mjwsteenbergen
Copy link
Contributor

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? ;)

@hallem hallem changed the title [Bug] Adding a manual User-Agent get overwritten by the User-Agent of the RestClient Adding a manual User-Agent get overwritten by the User-Agent of the RestClient Jan 28, 2016
@hallem
Copy link
Member

hallem commented Jan 28, 2016

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

@wing328
Copy link

wing328 commented Mar 15, 2016

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

RestClient.UserAgent = "test_user_agent";

(where RestClient is an instance of RestClient)

@mjwsteenbergen
Copy link
Contributor Author

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.

@Ashthos
Copy link

Ashthos commented May 13, 2016

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.

@Ariex
Copy link

Ariex commented Jun 24, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants