Skip to content

Commit 1912f1c

Browse files
committed
Don't overwrite http user agent with default
If a user overrides the IHttpFactory, RestCLient shouldn't overwrite the default user agent with its own unless both the RestClient and the Http instance both have not set the user agent to a proper value.
1 parent 3e5282b commit 1912f1c

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

RestSharp/RestClient.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ namespace RestSharp
3434
/// </summary>
3535
public partial class RestClient : IRestClient
3636
{
37+
// silverlight friendly way to get current version
38+
static readonly Version version = new AssemblyName(Assembly.GetExecutingAssembly().FullName).Version;
39+
3740
public IHttpFactory HttpFactory = new SimpleFactory<Http>();
3841

3942
/// <summary>
@@ -57,12 +60,6 @@ public RestClient()
5760
AddHandler("text/xml", new XmlDeserializer());
5861
AddHandler("*", new XmlDeserializer());
5962

60-
// silverlight friendly way to get current version
61-
var assembly = Assembly.GetExecutingAssembly();
62-
AssemblyName assemblyName = new AssemblyName(assembly.FullName);
63-
var version = assemblyName.Version;
64-
65-
UserAgent = "RestSharp " + version.ToString();
6663
FollowRedirects = true;
6764
}
6865

@@ -363,11 +360,9 @@ private void ConfigureHttp(IRestRequest request, IHttp http)
363360
}
364361

365362
http.Url = BuildUri(request);
366-
367-
if(UserAgent.HasValue())
368-
{
369-
http.UserAgent = UserAgent;
370-
}
363+
364+
var userAgent = UserAgent ?? http.UserAgent;
365+
http.UserAgent = userAgent.HasValue() ? userAgent : "RestSharp " + version.ToString();
371366

372367
var timeout = request.Timeout > 0 ? request.Timeout : Timeout;
373368
if (timeout > 0)

0 commit comments

Comments
 (0)