dnsimple/dnsimple-csharp

ChangeBaseUrlTo does not respect SetUserAgent

CumpsD opened this issue · 2 comments

I was looking through the code and saw this:

https://github.com/dnsimple/dnsimple-csharp/blob/master/src/dnsimple/DNSimple.cs#L332-L337

It seems this bit resets the user agent back to the default: RestClientWrapper.RestClient.UserAgent = DefaultUserAgent;

Which means this order will fail:

var r = new RestClientWrapper();
var client = new Client(r);

client.SetUserAgent("exira/1.0");
Console.WriteLine(r.RestClient.UserAgent);
client.ChangeBaseUrlTo("https://api.sandbox.dnsimple.com");
Console.WriteLine(r.RestClient.UserAgent);

While this will be ok:

var r = new RestClientWrapper();
var client = new Client(r);

client.ChangeBaseUrlTo("https://api.sandbox.dnsimple.com");
Console.WriteLine(r.RestClient.UserAgent);
client.SetUserAgent("exira/1.0");
Console.WriteLine(r.RestClient.UserAgent);

I am passing in the RestClientWrapper to check the UserAgent being used. Because the UserAgent property on Client will not show it

Thanks for the report @CumpsD. At first glance, it seems an oversight, I can't find any reason why we should set/reset the agent on URL change. This behavior doesn't exist in any other client.

We'll take a look shortly.

Thanks 👍