Last active
November 7, 2019 22:00
Revisions
-
flakey-bit renamed this gist
Nov 7, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
flakey-bit revised this gist
Nov 7, 2019 . No changes.There are no files selected for viewing
-
flakey-bit revised this gist
Nov 7, 2019 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,17 @@ public static Uri ComposeRequestUri(string baseUri, string pathSuffix=null, IDictionary<string, object> queryParameters=null) { if (string.IsNullOrEmpty(baseUri)) { throw new ArgumentException($"{nameof(baseUri)} is required", nameof(baseUri)); } var uri = new Uri(baseUri); if (!string.IsNullOrEmpty(pathSuffix)) { if (pathSuffix.StartsWith("/")) { throw new ArgumentException($"{nameof(pathSuffix)} must be relative"); } uri = new Uri(uri, pathSuffix); -
flakey-bit created this gist
Nov 7, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ public static Uri BuildRequestUri(string baseUri, string pathSuffix=null, IDictionary<string, object> queryParameters=null) { var uri = new Uri(baseUri); if (!string.IsNullOrEmpty(pathSuffix)) { if (pathSuffix.StartsWith("/")) { throw new ArgumentException("Path suffix must be relative"); } uri = new Uri(uri, pathSuffix); } var uriBuilder = new UriBuilder(uri); if (uriBuilder.Uri.IsDefaultPort) { uriBuilder.Port = -1; // Omit port in Uri if it's the default port for the scheme } if (queryParameters != null) { var query = System.Web.HttpUtility.ParseQueryString(uriBuilder.Query); foreach (var pair in queryParameters) { query[pair.Key] = pair.Value.ToString(); } uriBuilder.Query = query.ToString(); } return uriBuilder.Uri; }