From a01c011e11a9159b01b7e9147adb4f612defe718 Mon Sep 17 00:00:00 2001 From: pandaboy00 Date: Mon, 11 Jul 2016 15:35:42 -0400 Subject: [PATCH 01/13] seconds --- CSharpHTTPClient/Client.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CSharpHTTPClient/Client.cs b/CSharpHTTPClient/Client.cs index 84a3f46..46349bc 100644 --- a/CSharpHTTPClient/Client.cs +++ b/CSharpHTTPClient/Client.cs @@ -68,6 +68,7 @@ public class Client : DynamicObject public string Version; public string UrlPath; public string MediaType; + public TimeSpan Timeout; public enum Methods { DELETE, GET, PATCH, POST, PUT @@ -80,8 +81,9 @@ public enum Methods /// A dictionary of request headers /// API version, override AddVersion to customize /// Path to endpoint (e.g. /path/to/endpoint) + /// Set an Timeout parameter for the HTTP Client /// Fluent interface to a REST API - public Client(string host, Dictionary requestHeaders = null, string version = null, string urlPath = null) + public Client(string host, Dictionary requestHeaders = null, string version = null, string urlPath = null, TimeSpan? timeOut = null) { Host = host; if(requestHeaders != null) @@ -90,6 +92,7 @@ public Client(string host, Dictionary requestHeaders = null, stri } Version = (version != null) ? version : null; UrlPath = (urlPath != null) ? urlPath : null; + Timeout = (timeOut != null) ? (TimeSpan)timeOut : TimeSpan.FromSeconds(10); } /// @@ -155,7 +158,7 @@ private Client BuildClient(string name = null) } UrlPath = null; // Reset the current object's state before we return a new one - return new Client(Host, RequestHeaders, Version, endpoint); + return new Client(Host, RequestHeaders, Version, endpoint, Timeout); } @@ -261,6 +264,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o /// Response object public async virtual Task MakeRequest(HttpClient client, HttpRequestMessage request) { + HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false); return new Response(response.StatusCode, response.Content, response.Headers); } @@ -280,8 +284,10 @@ private async Task RequestAsync(string method, String requestBody = nu { // Build the URL client.BaseAddress = new Uri(Host); + client.Timeout = Timeout; string endpoint = BuildUrl(queryParams); + // Build the request headers client.DefaultRequestHeaders.Accept.Clear(); if(RequestHeaders != null) From f4d73af9625558b9b96522800f6e8f5007a1e41d Mon Sep 17 00:00:00 2001 From: pandaboy00 Date: Thu, 22 Sep 2016 09:08:45 -0400 Subject: [PATCH 02/13] Fixed conflict between MediaType and Timeout properties --- .gitignore | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..610a24a --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +CSharpHTTPClient/CSharpHTTPClient.sln.DotSettings.user +CSharpHTTPClient/bin/ +Example/bin/ +CSharpHTTPClient/obj/ +Example/obj/ +UnitTest/bin/ +UnitTest/obj/ +*.suo +CSharpHTTPClient/*/bin/ +CSharpHTTPClient/*/obj/ +.DS_store +CSharpHTTPClient/CSharpHTTPClient.userprefs +CSharpHTTPClient/packages/ +CSharpHTTPClient/CSharpHTTPClient.sln.VisualState.xml +*.PublicKey +*.pfx \ No newline at end of file From c9294dd591f24c894e19c0163e0ecdf98bab5d08 Mon Sep 17 00:00:00 2001 From: pandaboy00 Date: Thu, 22 Sep 2016 09:39:02 -0400 Subject: [PATCH 03/13] Merged MediaType and Timeout properties --- csharp-http-client | 1 + 1 file changed, 1 insertion(+) create mode 160000 csharp-http-client diff --git a/csharp-http-client b/csharp-http-client new file mode 160000 index 0000000..a9507f9 --- /dev/null +++ b/csharp-http-client @@ -0,0 +1 @@ +Subproject commit a9507f9bdec4c2f4e41d2810e179c53a9725f046 From 1d380063587bda599a71413394900526aefe56cc Mon Sep 17 00:00:00 2001 From: pandaboy00 Date: Thu, 22 Sep 2016 09:41:04 -0400 Subject: [PATCH 04/13] Merge conflict for MediaType and Timeout properties --- CSharpHTTPClient/Client.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CSharpHTTPClient/Client.cs b/CSharpHTTPClient/Client.cs index 84a3f46..ad48282 100644 --- a/CSharpHTTPClient/Client.cs +++ b/CSharpHTTPClient/Client.cs @@ -68,6 +68,7 @@ public class Client : DynamicObject public string Version; public string UrlPath; public string MediaType; + public TimeSpan Timeout; public enum Methods { DELETE, GET, PATCH, POST, PUT @@ -80,8 +81,9 @@ public enum Methods /// A dictionary of request headers /// API version, override AddVersion to customize /// Path to endpoint (e.g. /path/to/endpoint) + /// Set an Timeout parameter for the HTTP Client /// Fluent interface to a REST API - public Client(string host, Dictionary requestHeaders = null, string version = null, string urlPath = null) + public Client(string host, Dictionary requestHeaders = null, string version = null, string urlPath = null, TimeSpan? timeOut = null) { Host = host; if(requestHeaders != null) @@ -90,6 +92,7 @@ public Client(string host, Dictionary requestHeaders = null, stri } Version = (version != null) ? version : null; UrlPath = (urlPath != null) ? urlPath : null; + Timeout = (timeOut != null) ? (TimeSpan)timeOut : TimeSpan.FromSeconds(10); } /// @@ -155,7 +158,7 @@ private Client BuildClient(string name = null) } UrlPath = null; // Reset the current object's state before we return a new one - return new Client(Host, RequestHeaders, Version, endpoint); + return new Client(Host, RequestHeaders, Version, endpoint, Timeout); } @@ -261,6 +264,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o /// Response object public async virtual Task MakeRequest(HttpClient client, HttpRequestMessage request) { + HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false); return new Response(response.StatusCode, response.Content, response.Headers); } @@ -280,8 +284,10 @@ private async Task RequestAsync(string method, String requestBody = nu { // Build the URL client.BaseAddress = new Uri(Host); + client.Timeout = Timeout; string endpoint = BuildUrl(queryParams); + // Build the request headers client.DefaultRequestHeaders.Accept.Clear(); if(RequestHeaders != null) From 322a4c17b3c754171bcd5e2a8819c0b234487e4c Mon Sep 17 00:00:00 2001 From: pandaboy00 Date: Tue, 27 Sep 2016 11:45:26 -0400 Subject: [PATCH 05/13] Rechecked --- .gitignore | 2 +- .travis.yml | 2 ++ CHANGELOG.md | 1 + CONTRIBUTING.md | 2 +- LICENSE.txt | 1 + README.md | 1 + 6 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 610a24a..7dfead3 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ CSharpHTTPClient/CSharpHTTPClient.userprefs CSharpHTTPClient/packages/ CSharpHTTPClient/CSharpHTTPClient.sln.VisualState.xml *.PublicKey -*.pfx \ No newline at end of file +*.pfx diff --git a/.travis.yml b/.travis.yml index 24cb8ed..d02129b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,3 +18,5 @@ notifications: Build %{build_number} on branch %{branch} by %{author}: %{message} View on GitHub' format: html + + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 621ac41..f847c81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,3 +18,4 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [1.0.2] - 2016-03-17 ### Added - We are live! + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 30039ea..a728d6c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -162,4 +162,4 @@ Generally, we follow the style guidelines as suggested by the official language. 7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/) with a clear title and description against the `master` branch. All tests must be passing before we will review the PR. -If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo. \ No newline at end of file +If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo. diff --git a/LICENSE.txt b/LICENSE.txt index 9b2cba2..c1631d6 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/README.md b/README.md index 9fc4c8f..620cdb3 100644 --- a/README.md +++ b/README.md @@ -88,3 +88,4 @@ csharp-http-client is maintained and funded by SendGrid, Inc. The names and logo ![SendGrid Logo] (https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) + From f4f6596b3f07868af27ddc230040a006c73acf3b Mon Sep 17 00:00:00 2001 From: pandaboy00 Date: Wed, 28 Sep 2016 09:18:52 -0400 Subject: [PATCH 06/13] Remove csharp-http-client as it is extra --- csharp-http-client | 1 - 1 file changed, 1 deletion(-) delete mode 160000 csharp-http-client diff --git a/csharp-http-client b/csharp-http-client deleted file mode 160000 index a9507f9..0000000 --- a/csharp-http-client +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a9507f9bdec4c2f4e41d2810e179c53a9725f046 From cbb6884a0cc3f8a5773a2545004f40a246e463d0 Mon Sep 17 00:00:00 2001 From: pandaboy00 Date: Wed, 5 Oct 2016 09:15:54 -0400 Subject: [PATCH 07/13] Added new variable that stores a default value of 10 sec for TimeoutDefault --- CSharpHTTPClient/Client.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CSharpHTTPClient/Client.cs b/CSharpHTTPClient/Client.cs index 3fcf427..fd1856d 100644 --- a/CSharpHTTPClient/Client.cs +++ b/CSharpHTTPClient/Client.cs @@ -74,6 +74,8 @@ public enum Methods DELETE, GET, PATCH, POST, PUT } + private int TimeoutDefault = 10; + /// /// REST API client. /// @@ -92,7 +94,7 @@ public Client(string host, Dictionary requestHeaders = null, stri } Version = (version != null) ? version : null; UrlPath = (urlPath != null) ? urlPath : null; - Timeout = (timeOut != null) ? (TimeSpan)timeOut : TimeSpan.FromSeconds(10); + Timeout = (timeOut != null) ? (TimeSpan)timeOut : TimeSpan.FromSeconds(TimeoutDefault); } /// From f633ac1efee27accfc6f90a8af3a2c24dbaeda85 Mon Sep 17 00:00:00 2001 From: pandaboy00 Date: Thu, 6 Oct 2016 08:28:55 -0400 Subject: [PATCH 08/13] Reverted .travis.yml to commit 92f16b7 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d02129b..24cb8ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,5 +18,3 @@ notifications: Build %{build_number} on branch %{branch} by %{author}: %{message} View on GitHub' format: html - - \ No newline at end of file From 2fee721c6f6e94a1a513813750bebff745bbbef2 Mon Sep 17 00:00:00 2001 From: pandaboy00 Date: Thu, 6 Oct 2016 08:36:11 -0400 Subject: [PATCH 09/13] Revert .travis.yml back to commit 92f16b7 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d02129b..24cb8ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,5 +18,3 @@ notifications: Build %{build_number} on branch %{branch} by %{author}: %{message} View on GitHub' format: html - - \ No newline at end of file From c55e2d3994fbe5d518509ae776057471ad3cfcaa Mon Sep 17 00:00:00 2001 From: PandaBoy00 Date: Thu, 6 Oct 2016 08:52:31 -0400 Subject: [PATCH 10/13] Revert back to origin file --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d02129b..24cb8ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,5 +18,3 @@ notifications: Build %{build_number} on branch %{branch} by %{author}: %{message} View on GitHub' format: html - - \ No newline at end of file From 67d1d7cb4b1b7d88528cd744e51b4aa9b5f5024e Mon Sep 17 00:00:00 2001 From: pandaboy00 Date: Wed, 2 Nov 2016 11:58:27 -0400 Subject: [PATCH 11/13] Added TimeoutDefault value to 10 seconds --- CSharpHTTPClient/Client.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/CSharpHTTPClient/Client.cs b/CSharpHTTPClient/Client.cs index ea889c3..d6896dd 100644 --- a/CSharpHTTPClient/Client.cs +++ b/CSharpHTTPClient/Client.cs @@ -68,11 +68,8 @@ public class Client : DynamicObject public string Version; public string UrlPath; public string MediaType; -<<<<<<< HEAD - public TimeSpan Timeout; -======= public TimeSpan Timeout; ->>>>>>> a01c011e11a9159b01b7e9147adb4f612defe718 + public enum Methods { DELETE, GET, PATCH, POST, PUT @@ -98,11 +95,7 @@ public Client(string host, Dictionary requestHeaders = null, stri } Version = (version != null) ? version : null; UrlPath = (urlPath != null) ? urlPath : null; -<<<<<<< HEAD Timeout = (timeOut != null) ? (TimeSpan)timeOut : TimeSpan.FromSeconds(TimeoutDefault); -======= - Timeout = (timeOut != null) ? (TimeSpan)timeOut : TimeSpan.FromSeconds(10); ->>>>>>> a01c011e11a9159b01b7e9147adb4f612defe718 } /// From d9eee1a94aa94026c42b359f6aa645e37f8c7d4b Mon Sep 17 00:00:00 2001 From: pandaboy00 Date: Tue, 11 Apr 2017 11:44:16 -0400 Subject: [PATCH 12/13] Fixed Conflict --- CSharpHTTPClient/Client.cs | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/CSharpHTTPClient/Client.cs b/CSharpHTTPClient/Client.cs index d6896dd..b839ae9 100644 --- a/CSharpHTTPClient/Client.cs +++ b/CSharpHTTPClient/Client.cs @@ -63,11 +63,13 @@ public virtual Dictionary DeserializeResponseHeaders(HttpRespons public class Client : DynamicObject { + private static HttpClient _httpClient = new HttpClient(); public string Host; public Dictionary RequestHeaders; public string Version; public string UrlPath; public string MediaType; + public WebProxy WebProxy; public TimeSpan Timeout; public enum Methods @@ -77,6 +79,21 @@ public enum Methods private int TimeoutDefault = 10; + /// + /// REST API client. + /// + /// Base url (e.g. https://api.sendgrid.com) + /// A dictionary of request headers + /// API version, override AddVersion to customize + /// Path to endpoint (e.g. /path/to/endpoint) + /// Fluent interface to a REST API + public Client(WebProxy webProxy, string host, Dictionary requestHeaders = null, string version = null, string urlPath = null) + : this(host, requestHeaders, version, urlPath) + { + WebProxy = webProxy; + } + + /// /// REST API client. /// @@ -165,6 +182,29 @@ private Client BuildClient(string name = null) } + /// Factory method to return the right HttpClient settings. + /// + /// Instance of HttpClient + private HttpClient BuildHttpClient() + { + // Add the WebProxy if set + if (WebProxy != null) + { + var httpClientHandler = new HttpClientHandler() + { + Proxy = WebProxy, + PreAuthenticate = true, + UseDefaultCredentials = false, + }; + + return new HttpClient(httpClientHandler); + } + + return _httpClient; + } + + /// + /// /// Add the authorization header, override to customize /// From 7204b8ee62204e2c7b04ab45a5c11d1f77b1def2 Mon Sep 17 00:00:00 2001 From: pandaboy00 Date: Tue, 11 Apr 2017 13:29:00 -0400 Subject: [PATCH 13/13] Fixed Build Error --- CSharpHTTPClient/Client.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CSharpHTTPClient/Client.cs b/CSharpHTTPClient/Client.cs index b839ae9..fb7bd33 100644 --- a/CSharpHTTPClient/Client.cs +++ b/CSharpHTTPClient/Client.cs @@ -288,7 +288,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o } i++; } - result = RequestAsync(binder.Name.ToUpper(), requestBody: requestBody, queryParams: queryParams).Result; + result = RequestAsync(binder.Name.ToUpper(), requestBody: requestBody, queryParams: queryParams).ConfigureAwait(false); return true; } else @@ -357,7 +357,7 @@ private async Task RequestAsync(string method, String requestBody = nu StringContent content = null; if (requestBody != null) { - content = new StringContent(requestBody.ToString().Replace("'", "\""), Encoding.UTF8, MediaType); + content = new StringContent(requestBody, Encoding.UTF8, MediaType); } // Build the final request