Permalink
Browse files

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.
  • Loading branch information...
Haacked committed Aug 5, 2012
1 parent 3e5282b commit 1912f1c07433b92a327b64e7d4261d330a431cb5
Showing with 6 additions and 11 deletions.
  1. +6 −11 RestSharp/RestClient.cs
View
@@ -34,6 +34,9 @@ namespace RestSharp
/// </summary>
public partial class RestClient : IRestClient
{
+ // silverlight friendly way to get current version
+ static readonly Version version = new AssemblyName(Assembly.GetExecutingAssembly().FullName).Version;
+
public IHttpFactory HttpFactory = new SimpleFactory<Http>();
/// <summary>
@@ -57,12 +60,6 @@ public RestClient()
AddHandler("text/xml", new XmlDeserializer());
AddHandler("*", new XmlDeserializer());
- // silverlight friendly way to get current version
- var assembly = Assembly.GetExecutingAssembly();
- AssemblyName assemblyName = new AssemblyName(assembly.FullName);
- var version = assemblyName.Version;
-
- UserAgent = "RestSharp " + version.ToString();
FollowRedirects = true;
}
@@ -363,11 +360,9 @@ private void ConfigureHttp(IRestRequest request, IHttp http)
}
http.Url = BuildUri(request);
-
- if(UserAgent.HasValue())
- {
- http.UserAgent = UserAgent;
- }
+
+ var userAgent = UserAgent ?? http.UserAgent;
+ http.UserAgent = userAgent.HasValue() ? userAgent : "RestSharp " + version.ToString();
var timeout = request.Timeout > 0 ? request.Timeout : Timeout;
if (timeout > 0)

0 comments on commit 1912f1c

Please sign in to comment.