From 3e5282b4245bd14f7773447f75b8d7fcbbaff58c Mon Sep 17 00:00:00 2001 From: Haacked Date: Sat, 4 Aug 2012 20:50:04 -0700 Subject: [PATCH 1/2] Fix problem with setting request timeout The original code could override the http.Timeout with the value of 0 if the RestClient Timeout property was 0. If RestClient.Timeout <= 0, it shouldn't override the http.Timeout. --- RestSharp/RestClient.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/RestSharp/RestClient.cs b/RestSharp/RestClient.cs index 2a0e873dc..f0fa7d110 100644 --- a/RestSharp/RestClient.cs +++ b/RestSharp/RestClient.cs @@ -369,7 +369,11 @@ private void ConfigureHttp(IRestRequest request, IHttp http) http.UserAgent = UserAgent; } - http.Timeout = request.Timeout == 0 ? Timeout : request.Timeout; + var timeout = request.Timeout > 0 ? request.Timeout : Timeout; + if (timeout > 0) + { + http.Timeout = timeout; + } #if !SILVERLIGHT http.FollowRedirects = FollowRedirects; From 1912f1c07433b92a327b64e7d4261d330a431cb5 Mon Sep 17 00:00:00 2001 From: Haacked Date: Sat, 4 Aug 2012 21:19:11 -0700 Subject: [PATCH 2/2] 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. --- RestSharp/RestClient.cs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/RestSharp/RestClient.cs b/RestSharp/RestClient.cs index f0fa7d110..15c9bfa2b 100644 --- a/RestSharp/RestClient.cs +++ b/RestSharp/RestClient.cs @@ -34,6 +34,9 @@ namespace RestSharp /// 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(); /// @@ -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)