From 99331a46fd3cfde4653f7c0d7f4eb0f0bf9882cb Mon Sep 17 00:00:00 2001 From: Todd Menier Date: Tue, 19 Dec 2017 17:27:16 -0600 Subject: [PATCH 01/11] updated package testers to latest Flurl.Http --- .../PackageTester.NET45/PackageTester.NET45.csproj | 8 ++++---- PackageTesters/PackageTester.NET45/packages.config | 4 ++-- .../PackageTester.NET461/PackageTester.NET461.csproj | 8 ++++---- PackageTesters/PackageTester.NET461/packages.config | 4 ++-- .../PackageTester.NETCore/PackageTester.NETCore.csproj | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/PackageTesters/PackageTester.NET45/PackageTester.NET45.csproj b/PackageTesters/PackageTester.NET45/PackageTester.NET45.csproj index dfecf7f8..6d235b4f 100644 --- a/PackageTesters/PackageTester.NET45/PackageTester.NET45.csproj +++ b/PackageTesters/PackageTester.NET45/PackageTester.NET45.csproj @@ -31,11 +31,11 @@ 4 - - ..\..\packages\Flurl.2.5.1\lib\net40\Flurl.dll + + ..\..\packages\Flurl.2.6.0\lib\net45\Flurl.dll - - ..\..\packages\Flurl.Http.2.1.0\lib\net45\Flurl.Http.dll + + ..\..\packages\Flurl.Http.2.1.1\lib\net45\Flurl.Http.dll ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/PackageTesters/PackageTester.NET45/packages.config b/PackageTesters/PackageTester.NET45/packages.config index 424784dc..8ad1c134 100644 --- a/PackageTesters/PackageTester.NET45/packages.config +++ b/PackageTesters/PackageTester.NET45/packages.config @@ -1,6 +1,6 @@  - - + + \ No newline at end of file diff --git a/PackageTesters/PackageTester.NET461/PackageTester.NET461.csproj b/PackageTesters/PackageTester.NET461/PackageTester.NET461.csproj index f41ae75d..7fe7627e 100644 --- a/PackageTesters/PackageTester.NET461/PackageTester.NET461.csproj +++ b/PackageTesters/PackageTester.NET461/PackageTester.NET461.csproj @@ -33,11 +33,11 @@ 4 - - ..\..\packages\Flurl.2.5.1\lib\net40\Flurl.dll + + ..\..\packages\Flurl.2.6.0\lib\net45\Flurl.dll - - ..\..\packages\Flurl.Http.2.1.0\lib\net45\Flurl.Http.dll + + ..\..\packages\Flurl.Http.2.1.1\lib\net45\Flurl.Http.dll ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/PackageTesters/PackageTester.NET461/packages.config b/PackageTesters/PackageTester.NET461/packages.config index ad095dcb..2150c446 100644 --- a/PackageTesters/PackageTester.NET461/packages.config +++ b/PackageTesters/PackageTester.NET461/packages.config @@ -1,6 +1,6 @@  - - + + \ No newline at end of file diff --git a/PackageTesters/PackageTester.NETCore/PackageTester.NETCore.csproj b/PackageTesters/PackageTester.NETCore/PackageTester.NETCore.csproj index 672a2957..0d35e6e1 100644 --- a/PackageTesters/PackageTester.NETCore/PackageTester.NETCore.csproj +++ b/PackageTesters/PackageTester.NETCore/PackageTester.NETCore.csproj @@ -8,7 +8,7 @@ - + \ No newline at end of file From 9fd1ffefb14d3310a96f9e9273bdffcff251bad6 Mon Sep 17 00:00:00 2001 From: Todd Menier Date: Mon, 1 Jan 2018 12:00:43 -0600 Subject: [PATCH 02/11] #266 automatic decompression --- Test/Flurl.Test/Http/RealHttpTests.cs | 13 +++++++++++++ .../Configuration/DefaultHttpClientFactory.cs | 6 +++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Test/Flurl.Test/Http/RealHttpTests.cs b/Test/Flurl.Test/Http/RealHttpTests.cs index 2c26539d..181fa78b 100644 --- a/Test/Flurl.Test/Http/RealHttpTests.cs +++ b/Test/Flurl.Test/Http/RealHttpTests.cs @@ -17,6 +17,19 @@ namespace Flurl.Test.Http [TestFixture, Parallelizable] public class RealHttpTests { + [TestCase("gzip")] + [TestCase("deflate")] + public async Task decompresses_automatically(string encoding) { + var page = DateTime.Now.Ticks % 10 + 1; // vary it a bit to avoid possible rate limit errors + Console.WriteLine(page); + dynamic d2 = await $"https://api.stackexchange.com/2.2/answers?site=stackoverflow&pagesize=10&page={page}" + .WithHeader("Accept-Encoding", encoding) + .GetJsonAsync(); + + Assert.AreEqual(10, d2.items.Count); + Assert.IsTrue(d2.has_more); + } + [Test] public async Task can_download_file() { var folder = "c:\\flurl-test-" + Guid.NewGuid(); // random so parallel tests don't trip over each other diff --git a/src/Flurl.Http/Configuration/DefaultHttpClientFactory.cs b/src/Flurl.Http/Configuration/DefaultHttpClientFactory.cs index 44396763..0e5fc956 100644 --- a/src/Flurl.Http/Configuration/DefaultHttpClientFactory.cs +++ b/src/Flurl.Http/Configuration/DefaultHttpClientFactory.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Net.Http; namespace Flurl.Http.Configuration @@ -28,7 +29,10 @@ public virtual HttpClient CreateHttpClient(HttpMessageHandler handler) { /// customize the result. /// public virtual HttpMessageHandler CreateMessageHandler() { - return new HttpClientHandler(); + return new HttpClientHandler { + // #266 + AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate + }; } } } \ No newline at end of file From e4bf5e9c2be29d4645b51b5ef4a379628cf48469 Mon Sep 17 00:00:00 2001 From: Nikolay Molchanov Date: Sat, 17 Feb 2018 16:15:13 +0300 Subject: [PATCH 03/11] [add] netstd2.0 target --- src/Flurl.Http/Flurl.Http.csproj | 6 +++++- src/Flurl.Http/HttpResponseMessageExtensions.cs | 6 +++--- src/Flurl.Http/Testing/HttpTest.cs | 4 ++-- src/Flurl/Flurl.csproj | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Flurl.Http/Flurl.Http.csproj b/src/Flurl.Http/Flurl.Http.csproj index 35566e42..a470daf4 100644 --- a/src/Flurl.Http/Flurl.Http.csproj +++ b/src/Flurl.Http/Flurl.Http.csproj @@ -1,7 +1,7 @@  - net45;netstandard1.3;netstandard1.1; + net45;netstandard1.3;netstandard1.1;netstandard2.0; True Flurl.Http 2.0.1 @@ -35,6 +35,10 @@ + + + + diff --git a/src/Flurl.Http/HttpResponseMessageExtensions.cs b/src/Flurl.Http/HttpResponseMessageExtensions.cs index 6c6eb305..6dde57fc 100644 --- a/src/Flurl.Http/HttpResponseMessageExtensions.cs +++ b/src/Flurl.Http/HttpResponseMessageExtensions.cs @@ -3,7 +3,7 @@ using System.Dynamic; using System.IO; using System.Net.Http; -#if NETSTANDARD1_3 +#if NETSTANDARD1_3 || NETSTANDARD2_0 using System.Text; #endif using System.Threading.Tasks; @@ -64,10 +64,10 @@ public static async Task> ReceiveJsonList(this TaskA Task whose result is the response body as a string. /// s = await url.PostAsync(data).ReceiveString() public static async Task ReceiveString(this Task response) { -#if NETSTANDARD1_3 +#if NETSTANDARD1_3 || NETSTANDARD2_0 Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); #endif - var resp = await response.ConfigureAwait(false); + var resp = await response.ConfigureAwait(false); if (resp == null) return null; return await resp.Content.StripCharsetQuotes().ReadAsStringAsync().ConfigureAwait(false); diff --git a/src/Flurl.Http/Testing/HttpTest.cs b/src/Flurl.Http/Testing/HttpTest.cs index da8adc95..b63936f3 100644 --- a/src/Flurl.Http/Testing/HttpTest.cs +++ b/src/Flurl.Http/Testing/HttpTest.cs @@ -171,7 +171,7 @@ public void Dispose() { #if NET45 private static void SetCurrentTest(HttpTest test) => System.Runtime.Remoting.Messaging.CallContext.LogicalSetData("FlurlHttpTest", test); private static HttpTest GetCurrentTest() => System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("FlurlHttpTest") as HttpTest; -#elif NETSTANDARD1_3 +#elif NETSTANDARD1_3 || NETSTANDARD2_0 private static System.Threading.AsyncLocal _test = new System.Threading.AsyncLocal(); private static void SetCurrentTest(HttpTest test) => _test.Value = test; private static HttpTest GetCurrentTest() => _test.Value; @@ -180,5 +180,5 @@ public void Dispose() { private static void SetCurrentTest(HttpTest test) => _test = test; private static HttpTest GetCurrentTest() => _test; #endif - } + } } \ No newline at end of file diff --git a/src/Flurl/Flurl.csproj b/src/Flurl/Flurl.csproj index 783170d7..e0d18617 100644 --- a/src/Flurl/Flurl.csproj +++ b/src/Flurl/Flurl.csproj @@ -1,7 +1,7 @@  - net40;netstandard1.3;netstandard1.0; + net40;netstandard1.3;netstandard1.0;netstandard2.0; True Flurl 2.5.0 From 67d21f11e4ed8f02fbb4d59a25d2412f3d043dc2 Mon Sep 17 00:00:00 2001 From: Nikolay Molchanov Date: Sat, 17 Feb 2018 16:25:21 +0300 Subject: [PATCH 04/11] bump versions --- .../PackageTester.NET45/PackageTester.NET45.csproj | 8 ++++---- PackageTesters/PackageTester.NET45/packages.config | 4 ++-- .../PackageTester.NET461/PackageTester.NET461.csproj | 8 ++++---- PackageTesters/PackageTester.NET461/packages.config | 4 ++-- .../PackageTester.NETCore/PackageTester.NETCore.csproj | 4 ++-- Test/Flurl.Test/Flurl.Test.csproj | 8 ++++---- src/Flurl.Http.CodeGen/Flurl.Http.CodeGen.csproj | 2 +- src/Flurl.Http/Flurl.Http.csproj | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/PackageTesters/PackageTester.NET45/PackageTester.NET45.csproj b/PackageTesters/PackageTester.NET45/PackageTester.NET45.csproj index 9264b453..6d235b4f 100644 --- a/PackageTesters/PackageTester.NET45/PackageTester.NET45.csproj +++ b/PackageTesters/PackageTester.NET45/PackageTester.NET45.csproj @@ -31,11 +31,11 @@ 4 - - ..\..\packages\Flurl.2.5.0\lib\net40\Flurl.dll + + ..\..\packages\Flurl.2.6.0\lib\net45\Flurl.dll - - ..\..\packages\Flurl.Http.2.0.1\lib\net45\Flurl.Http.dll + + ..\..\packages\Flurl.Http.2.1.1\lib\net45\Flurl.Http.dll ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/PackageTesters/PackageTester.NET45/packages.config b/PackageTesters/PackageTester.NET45/packages.config index 156c06e4..8ad1c134 100644 --- a/PackageTesters/PackageTester.NET45/packages.config +++ b/PackageTesters/PackageTester.NET45/packages.config @@ -1,6 +1,6 @@  - - + + \ No newline at end of file diff --git a/PackageTesters/PackageTester.NET461/PackageTester.NET461.csproj b/PackageTesters/PackageTester.NET461/PackageTester.NET461.csproj index 5327b29a..7fe7627e 100644 --- a/PackageTesters/PackageTester.NET461/PackageTester.NET461.csproj +++ b/PackageTesters/PackageTester.NET461/PackageTester.NET461.csproj @@ -33,11 +33,11 @@ 4 - - ..\..\packages\Flurl.2.5.0\lib\net40\Flurl.dll + + ..\..\packages\Flurl.2.6.0\lib\net45\Flurl.dll - - ..\..\packages\Flurl.Http.2.0.1\lib\net45\Flurl.Http.dll + + ..\..\packages\Flurl.Http.2.1.1\lib\net45\Flurl.Http.dll ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/PackageTesters/PackageTester.NET461/packages.config b/PackageTesters/PackageTester.NET461/packages.config index 6dc8ed8f..2150c446 100644 --- a/PackageTesters/PackageTester.NET461/packages.config +++ b/PackageTesters/PackageTester.NET461/packages.config @@ -1,6 +1,6 @@  - - + + \ No newline at end of file diff --git a/PackageTesters/PackageTester.NETCore/PackageTester.NETCore.csproj b/PackageTesters/PackageTester.NETCore/PackageTester.NETCore.csproj index b3c5468e..abdf2d5c 100644 --- a/PackageTesters/PackageTester.NETCore/PackageTester.NETCore.csproj +++ b/PackageTesters/PackageTester.NETCore/PackageTester.NETCore.csproj @@ -2,13 +2,13 @@ Exe - netcoreapp1.1 + netcoreapp2.0 - + \ No newline at end of file diff --git a/Test/Flurl.Test/Flurl.Test.csproj b/Test/Flurl.Test/Flurl.Test.csproj index b35ff87a..1026a58f 100644 --- a/Test/Flurl.Test/Flurl.Test.csproj +++ b/Test/Flurl.Test/Flurl.Test.csproj @@ -1,13 +1,13 @@  - net45;netcoreapp1.1; + net45;netcoreapp2.0; - - - + + + diff --git a/src/Flurl.Http.CodeGen/Flurl.Http.CodeGen.csproj b/src/Flurl.Http.CodeGen/Flurl.Http.CodeGen.csproj index 6d25f413..f94b956a 100644 --- a/src/Flurl.Http.CodeGen/Flurl.Http.CodeGen.csproj +++ b/src/Flurl.Http.CodeGen/Flurl.Http.CodeGen.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp1.1 + netcoreapp2.0 \ No newline at end of file diff --git a/src/Flurl.Http/Flurl.Http.csproj b/src/Flurl.Http/Flurl.Http.csproj index a470daf4..2e95a0d9 100644 --- a/src/Flurl.Http/Flurl.Http.csproj +++ b/src/Flurl.Http/Flurl.Http.csproj @@ -27,7 +27,7 @@ - + From c15a92f0339a14c28ac2f5b8d9d459cb65240bfb Mon Sep 17 00:00:00 2001 From: Nikolay Molchanov Date: Sat, 17 Feb 2018 16:27:57 +0300 Subject: [PATCH 05/11] level up versions of packages --- src/Flurl.Http/Flurl.Http.csproj | 2 +- src/Flurl/Flurl.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Flurl.Http/Flurl.Http.csproj b/src/Flurl.Http/Flurl.Http.csproj index 2e95a0d9..e91c9ccd 100644 --- a/src/Flurl.Http/Flurl.Http.csproj +++ b/src/Flurl.Http/Flurl.Http.csproj @@ -4,7 +4,7 @@ net45;netstandard1.3;netstandard1.1;netstandard2.0; True Flurl.Http - 2.0.1 + 2.1.2 Todd Menier WARNING: 2.0 CONTAINS BREAKING CHANGES - REVIEW RELEASE NOTES CAREFULLY! Flurl.Http is a fluent, portable, testable HTTP client library that extends Flurl's URL builder chain. http://tmenier.github.io/Flurl diff --git a/src/Flurl/Flurl.csproj b/src/Flurl/Flurl.csproj index e0d18617..35b03048 100644 --- a/src/Flurl/Flurl.csproj +++ b/src/Flurl/Flurl.csproj @@ -4,7 +4,7 @@ net40;netstandard1.3;netstandard1.0;netstandard2.0; True Flurl - 2.5.0 + 2.6.1 Todd Menier A fluent, portable URL builder. To make HTTP calls off the fluent chain, check out Flurl.Http. http://tmenier.github.io/Flurl From 910260daf788ecfbbb589155c68f4b182ad1e75a Mon Sep 17 00:00:00 2001 From: Todd Menier Date: Sat, 17 Feb 2018 11:06:07 -0600 Subject: [PATCH 06/11] test for #266 was occasionally bumping up against StackExchange rate limits --- Test/Flurl.Test/Http/RealHttpTests.cs | 30 +++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Test/Flurl.Test/Http/RealHttpTests.cs b/Test/Flurl.Test/Http/RealHttpTests.cs index 181fa78b..4a16628d 100644 --- a/Test/Flurl.Test/Http/RealHttpTests.cs +++ b/Test/Flurl.Test/Http/RealHttpTests.cs @@ -17,17 +17,35 @@ namespace Flurl.Test.Http [TestFixture, Parallelizable] public class RealHttpTests { + class StackExResponse + { + public object[] items { get; set; } + public bool has_more { get; set; } + public int backoff { get; set; } + + internal static int last_page = 0; + internal static int last_backoff = 0; + } + [TestCase("gzip")] [TestCase("deflate")] + [NonParallelizable] public async Task decompresses_automatically(string encoding) { - var page = DateTime.Now.Ticks % 10 + 1; // vary it a bit to avoid possible rate limit errors - Console.WriteLine(page); - dynamic d2 = await $"https://api.stackexchange.com/2.2/answers?site=stackoverflow&pagesize=10&page={page}" + if (StackExResponse.last_backoff > 0) { + Console.WriteLine($"Backing off StackExchange for {StackExResponse.last_backoff} seconds..."); + await Task.Delay(TimeSpan.FromSeconds(StackExResponse.last_backoff)); + } + + StackExResponse.last_page++; + var result = await $"https://api.stackexchange.com/2.2/answers?site=stackoverflow&pagesize=10" + .SetQueryParam("page", ++StackExResponse.last_page) .WithHeader("Accept-Encoding", encoding) - .GetJsonAsync(); + .GetJsonAsync(); + + StackExResponse.last_backoff = result.backoff; - Assert.AreEqual(10, d2.items.Count); - Assert.IsTrue(d2.has_more); + Assert.AreEqual(10, result.items.Length); + Assert.IsTrue(result.has_more); } [Test] From c088cefdb326b586423a50ae392395aa3d0b9766 Mon Sep 17 00:00:00 2001 From: Todd Menier Date: Sat, 17 Feb 2018 11:50:54 -0600 Subject: [PATCH 07/11] #272 encode illegal characters only (not reserved) in query param names --- Test/Flurl.Test/UrlBuilderTests.cs | 8 +++++++- src/Flurl/QueryParameter.cs | 2 +- src/Flurl/Url.cs | 11 ++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Test/Flurl.Test/UrlBuilderTests.cs b/Test/Flurl.Test/UrlBuilderTests.cs index 19525f69..f24ddffc 100644 --- a/Test/Flurl.Test/UrlBuilderTests.cs +++ b/Test/Flurl.Test/UrlBuilderTests.cs @@ -279,7 +279,7 @@ public void encodes_illegal_path_chars() { } [Test] - public void can_encodes_reserved_path_chars() { + public void can_encode_reserved_path_chars() { // should encode '/' (tests optional fullyEncode arg) var url = "http://www.mysite.com".AppendPathSegment("hi there/bye now", true); Assert.AreEqual("http://www.mysite.com/hi%20there%2Fbye%20now", url.ToString()); @@ -309,6 +309,12 @@ public void reencodes_encoded_query_values_when_isEncoded_false() { Assert.AreEqual("http://www.mysite.com?x=%25CD%25EE%25E2%25FB%25E9%2520%25E3%25EE%25E4", url.ToString()); } + [Test] + public void does_not_encode_reserved_chars_in_query_param_name() { + var url = "http://www.mysite.com".SetQueryParam("$x", 1); + Assert.AreEqual("http://www.mysite.com?$x=1", url.ToString()); + } + [Test] public void Url_implicitly_converts_to_string() { var url = new Url("http://www.mysite.com/more?x=1&y=2"); diff --git a/src/Flurl/QueryParameter.cs b/src/Flurl/QueryParameter.cs index 2ddad43a..01f6a922 100644 --- a/src/Flurl/QueryParameter.cs +++ b/src/Flurl/QueryParameter.cs @@ -61,7 +61,7 @@ from v in (_value as IEnumerable).Cast() } private static string BuildPair(string name, object value, bool valueIsEncoded, bool encodeSpaceAsPlus) { - name = Url.Encode(name, encodeSpaceAsPlus); + name = Url.EncodeIllegalCharacters(name, encodeSpaceAsPlus); if (value == null) return name; diff --git a/src/Flurl/Url.cs b/src/Flurl/Url.cs index 1743900d..f6fc7b9e 100644 --- a/src/Flurl/Url.cs +++ b/src/Flurl/Url.cs @@ -139,8 +139,8 @@ public static string Decode(string s, bool interpretPlusAsSpace) { /// /// The string to encode. /// If true, spaces will be encoded as + signs. Otherwise, they'll be encoded as %20. - /// - public static string Encode(string s, bool encodeSpaceAsPlus) { + /// The encoded URL. + public static string Encode(string s, bool encodeSpaceAsPlus = false) { if (string.IsNullOrEmpty(s)) return s; @@ -164,10 +164,15 @@ public static string Encode(string s, bool encodeSpaceAsPlus) { /// URL-encodes characters in a string that are neither reserved nor unreserved. Avoids encoding reserved characters such as '/' and '?'. Avoids encoding '%' if it begins a %-hex-hex sequence (i.e. avoids double-encoding). /// /// The string to encode. - public static string EncodeIllegalCharacters(string s) { + /// If true, spaces will be encoded as + signs. Otherwise, they'll be encoded as %20. + /// The encoded URL. + public static string EncodeIllegalCharacters(string s, bool encodeSpaceAsPlus = false) { if (string.IsNullOrEmpty(s)) return s; + if (encodeSpaceAsPlus) + s = s.Replace(" ", "+"); + // Uri.EscapeUriString mostly does what we want - encodes illegal characters only - but it has a quirk // in that % isn't illegal if it's the start of a %-encoded sequence https://stackoverflow.com/a/47636037/62600 From fc288ab2a872388ed24b16d2e4d8fb4b89b18be6 Mon Sep 17 00:00:00 2001 From: Todd Menier Date: Sat, 17 Feb 2018 18:02:39 -0600 Subject: [PATCH 08/11] #269 TestFlurlClientFactory deemed unnecessary --- .../Configuration/FlurlHttpSettings.cs | 10 ---- src/Flurl.Http/Testing/TestFactories.cs | 46 ------------------- .../Testing/TestHttpClientFactory.cs | 20 ++++++++ 3 files changed, 20 insertions(+), 56 deletions(-) delete mode 100644 src/Flurl.Http/Testing/TestFactories.cs create mode 100644 src/Flurl.Http/Testing/TestHttpClientFactory.cs diff --git a/src/Flurl.Http/Configuration/FlurlHttpSettings.cs b/src/Flurl.Http/Configuration/FlurlHttpSettings.cs index 18d744ce..4e426332 100644 --- a/src/Flurl.Http/Configuration/FlurlHttpSettings.cs +++ b/src/Flurl.Http/Configuration/FlurlHttpSettings.cs @@ -224,21 +224,11 @@ public override void ResetDefaults() { /// public class TestFlurlHttpSettings : ClientFlurlHttpSettings { - /// - /// Gets or sets the factory that defines creating, caching, and reusing FlurlClient instances - /// within the context of this HttpTest - /// - public IFlurlClientFactory FlurlClientFactory { - get => Get(() => FlurlClientFactory); - set => Set(() => FlurlClientFactory, value); - } - /// /// Resets all test settings to their Flurl.Http-defined default values. /// public override void ResetDefaults() { base.ResetDefaults(); - FlurlClientFactory = new TestFlurlClientFactory(); HttpClientFactory = new TestHttpClientFactory(); } } diff --git a/src/Flurl.Http/Testing/TestFactories.cs b/src/Flurl.Http/Testing/TestFactories.cs deleted file mode 100644 index 98e6b5ac..00000000 --- a/src/Flurl.Http/Testing/TestFactories.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Net.Http; -using Flurl.Http.Configuration; - -namespace Flurl.Http.Testing -{ - /// - /// IHttpClientFactory implementation used to fake and record calls in tests. - /// - public class TestHttpClientFactory : DefaultHttpClientFactory - { - /// - /// Creates an instance of FakeHttpMessageHander, which prevents actual HTTP calls from being made. - /// - /// - public override HttpMessageHandler CreateMessageHandler() { - return new FakeHttpMessageHandler(); - } - } - - /// - /// IFlurlClientFactory implementation used to fake and record calls in tests. - /// - public class TestFlurlClientFactory : FlurlClientFactoryBase - { - private readonly Lazy _client = new Lazy(() => new FlurlClient()); - - /// - /// Returns the FlurlClient sigleton used for testing - /// - /// The URL. - /// The FlurlClient instance. - public override IFlurlClient Get(Url url) { - return _client.Value; - } - - /// - /// Not used. Singleton FlurlClient used for lifetime of test. - /// - /// - /// - protected override string GetCacheKey(Url url) { - return null; - } - } -} \ No newline at end of file diff --git a/src/Flurl.Http/Testing/TestHttpClientFactory.cs b/src/Flurl.Http/Testing/TestHttpClientFactory.cs new file mode 100644 index 00000000..b4a2b736 --- /dev/null +++ b/src/Flurl.Http/Testing/TestHttpClientFactory.cs @@ -0,0 +1,20 @@ +using System; +using System.Net.Http; +using Flurl.Http.Configuration; + +namespace Flurl.Http.Testing +{ + /// + /// IHttpClientFactory implementation used to fake and record calls in tests. + /// + public class TestHttpClientFactory : DefaultHttpClientFactory + { + /// + /// Creates an instance of FakeHttpMessageHander, which prevents actual HTTP calls from being made. + /// + /// + public override HttpMessageHandler CreateMessageHandler() { + return new FakeHttpMessageHandler(); + } + } +} \ No newline at end of file From 4c913ee385601680820b4a6f4dcf9dbe073fe04b Mon Sep 17 00:00:00 2001 From: Todd Menier Date: Sun, 18 Feb 2018 12:36:31 -0600 Subject: [PATCH 09/11] #207 fix for MSTest? --- src/Flurl.Http/Testing/HttpTest.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Flurl.Http/Testing/HttpTest.cs b/src/Flurl.Http/Testing/HttpTest.cs index 63f95708..0b710af5 100644 --- a/src/Flurl.Http/Testing/HttpTest.cs +++ b/src/Flurl.Http/Testing/HttpTest.cs @@ -13,6 +13,9 @@ namespace Flurl.Http.Testing /// An object whose existence puts Flurl.Http into test mode where actual HTTP calls are faked. Provides a response /// queue, call log, and assertion helpers for use in Arrange/Act/Assert style tests. /// +#if !NETSTANDARD1_1 + [Serializable] // fixes MSTest issue? #207 +#endif public class HttpTest : IDisposable { private readonly Lazy _httpClient; From f49fbe74621058fef06b6f85fedbcbd7f802e581 Mon Sep 17 00:00:00 2001 From: Todd Menier Date: Sun, 18 Feb 2018 12:49:23 -0600 Subject: [PATCH 10/11] a couple picky little changes for #267 --- src/Flurl.Http/Flurl.Http.csproj | 2 +- src/Flurl.Http/HttpResponseMessageExtensions.cs | 7 ++----- src/Flurl/Flurl.csproj | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Flurl.Http/Flurl.Http.csproj b/src/Flurl.Http/Flurl.Http.csproj index 03092cd7..adb96734 100644 --- a/src/Flurl.Http/Flurl.Http.csproj +++ b/src/Flurl.Http/Flurl.Http.csproj @@ -1,7 +1,7 @@  - net45;netstandard1.3;netstandard1.1;netstandard2.0; + net45;netstandard1.1;netstandard1.3;netstandard2.0; True Flurl.Http 2.1.2 diff --git a/src/Flurl.Http/HttpResponseMessageExtensions.cs b/src/Flurl.Http/HttpResponseMessageExtensions.cs index a7782eed..5d67d8f0 100644 --- a/src/Flurl.Http/HttpResponseMessageExtensions.cs +++ b/src/Flurl.Http/HttpResponseMessageExtensions.cs @@ -3,9 +3,6 @@ using System.Dynamic; using System.IO; using System.Net.Http; -#if NETSTANDARD1_3 || NETSTANDARD2_0 -using System.Text; -#endif using System.Threading.Tasks; using Flurl.Util; @@ -66,9 +63,9 @@ public static async Task> ReceiveJsonList(this Tasks = await url.PostAsync(data).ReceiveString() public static async Task ReceiveString(this Task response) { #if NETSTANDARD1_3 || NETSTANDARD2_0 - Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); #endif - var resp = await response.ConfigureAwait(false); + var resp = await response.ConfigureAwait(false); if (resp == null) return null; return await resp.Content.StripCharsetQuotes().ReadAsStringAsync().ConfigureAwait(false); diff --git a/src/Flurl/Flurl.csproj b/src/Flurl/Flurl.csproj index 4352aa46..7954355b 100644 --- a/src/Flurl/Flurl.csproj +++ b/src/Flurl/Flurl.csproj @@ -1,7 +1,7 @@  - net40;netstandard1.3;netstandard1.0;netstandard2.0; + net40;netstandard1.0;netstandard1.3;netstandard2.0; True Flurl 2.6.1 From d6b523932c4c2ed5c40eddc6c2d37966a8c9c009 Mon Sep 17 00:00:00 2001 From: Todd Menier Date: Sun, 18 Feb 2018 12:58:31 -0600 Subject: [PATCH 11/11] version bumps --- src/Flurl.Http/Flurl.Http.csproj | 4 ++-- src/Flurl/Flurl.csproj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Flurl.Http/Flurl.Http.csproj b/src/Flurl.Http/Flurl.Http.csproj index adb96734..d4826424 100644 --- a/src/Flurl.Http/Flurl.Http.csproj +++ b/src/Flurl.Http/Flurl.Http.csproj @@ -4,7 +4,7 @@ net45;netstandard1.1;netstandard1.3;netstandard2.0; True Flurl.Http - 2.1.2 + 2.2.0-pre1 Todd Menier Flurl.Http is a fluent, portable, testable HTTP client library that extends Flurl's URL builder chain. http://tmenier.github.io/Flurl @@ -27,7 +27,7 @@ - + diff --git a/src/Flurl/Flurl.csproj b/src/Flurl/Flurl.csproj index 7954355b..12ea057b 100644 --- a/src/Flurl/Flurl.csproj +++ b/src/Flurl/Flurl.csproj @@ -4,7 +4,7 @@ net40;netstandard1.0;netstandard1.3;netstandard2.0; True Flurl - 2.6.1 + 2.7.0-pre1 Todd Menier A fluent, portable URL builder. To make HTTP calls off the fluent chain, check out Flurl.Http. http://tmenier.github.io/Flurl