diff --git a/Build/nuspec/Flurl.Http.nuspec b/Build/nuspec/Flurl.Http.nuspec index 1ff59b56..78a358d3 100644 --- a/Build/nuspec/Flurl.Http.nuspec +++ b/Build/nuspec/Flurl.Http.nuspec @@ -2,7 +2,7 @@ Flurl.Http - 1.1.2 + 1.1.3 Flurl.Http Todd Menier http://tmenier.github.io/Flurl @@ -13,6 +13,7 @@ A fluent, portable, testable HTTP client library that extends Flurl's URL builder chain. +1.1.3 - Minor fixes (github #175, #182, #186) 1.1.2 - Minor bug fixes (github #159 & #169), up'd Flurl dependency to 2.3.0 1.1.1 - More query param assert variations (github #102), HttpCall.Url now a Flurl.Url instance 1.1.0 - Parallel testing (github #67), better DI/IoC/mocking support (github #146), assert query params (github #102) diff --git a/Test/Flurl.Test.Shared/Http/GetTests.cs b/Test/Flurl.Test.Shared/Http/GetTests.cs index 718cd4d7..1ae6e6f3 100644 --- a/Test/Flurl.Test.Shared/Http/GetTests.cs +++ b/Test/Flurl.Test.Shared/Http/GetTests.cs @@ -137,7 +137,20 @@ public async Task can_get_null_json_when_timeout_and_exception_handled() { Assert.IsNull(data); } - private class TestData + // https://github.com/tmenier/Flurl/pull/76 + // quotes around charset value is technically legal but there's a bug in .NET we want to avoid: https://github.com/dotnet/corefx/issues/5014 + [Test] + public async Task can_get_string_with_quoted_charset_header() { + var content = new StringContent("foo"); + content.Headers.Clear(); + content.Headers.Add("Content-Type", "text/javascript; charset=\"UTF-8\""); + HttpTest.RespondWith(content); + + var resp = await "http://api.com".GetStringAsync(); // without StripCharsetQuotes, this fails + Assert.AreEqual("foo", resp); + } + + private class TestData { public int id { get; set; } public string name { get; set; } diff --git a/Test/Flurl.Test.Shared/Http/RealHttpTests.cs b/Test/Flurl.Test.Shared/Http/RealHttpTests.cs index 62bf4095..762af15d 100644 --- a/Test/Flurl.Test.Shared/Http/RealHttpTests.cs +++ b/Test/Flurl.Test.Shared/Http/RealHttpTests.cs @@ -149,11 +149,16 @@ public async Task can_post_multipart() { try { using (var stream = File.OpenRead(path2)) { var resp = await "http://httpbin.org/post" - .PostMultipartAsync(content => content - .AddStringParts(new {a = 1, b = 2}) - .AddString("DataField", "hello!") - .AddFile("File1", path1) - .AddFile("File2", stream, "foo.txt")) + .PostMultipartAsync(content => { + content + .AddStringParts(new { a = 1, b = 2 }) + .AddString("DataField", "hello!") + .AddFile("File1", path1) + .AddFile("File2", stream, "foo.txt"); + + // hack to deal with #179, remove when this is fixed: https://github.com/kennethreitz/httpbin/issues/340 + content.Headers.ContentLength = 735; + }) //.ReceiveString(); .ReceiveJson(); Assert.AreEqual("1", resp.form.a); @@ -168,25 +173,6 @@ public async Task can_post_multipart() { } } - // https://github.com/tmenier/Flurl/pull/76 - // quotes around charset value is technically legal but there's a bug in .NET we want to avoid: https://github.com/dotnet/corefx/issues/5014 - [Test] - public async Task supports_quoted_charset() { - // Respond with header Content-Type: text/javascript; charset="UTF-8" - var url = "https://httpbin.org/response-headers?Content-Type=text/javascript;%20charset=%22UTF-8%22"; - - // confirm thart repsonse has quoted charset value - var resp = await url.GetAsync(); - Assert.AreEqual("\"UTF-8\"", resp.Content.Headers.ContentType.CharSet); - - // GetStringAsync is where we need to work around the .NET bug - var s = await url.GetStringAsync(); - // not throwing should be enough, but do a little more for good measure.. - s = s.Trim(); - StringAssert.StartsWith("{", s); - StringAssert.EndsWith("}", s); - } - [Test] public async Task can_handle_error() { var handlerCalled = false; diff --git a/Test/Flurl.Test.Shared/Http/TestingTests.cs b/Test/Flurl.Test.Shared/Http/TestingTests.cs index d2a77e19..e4b1b9e1 100644 --- a/Test/Flurl.Test.Shared/Http/TestingTests.cs +++ b/Test/Flurl.Test.Shared/Http/TestingTests.cs @@ -183,7 +183,19 @@ public async Task cannot_inspect_RequestBody_with_uncaptured_content() { } } -// parallel testing not supported in PCL + // https://github.com/tmenier/Flurl/issues/175 + [Test] + public async Task can_deserialize_default_response_more_than_once() { + var resp = await "http://www.api.com".GetJsonAsync(); + Assert.IsNull(resp); + // bug: couldn't deserialize here due to reading stream twice + resp = await "http://www.api.com".GetJsonAsync(); + Assert.IsNull(resp); + resp = await "http://www.api.com".GetJsonAsync(); + Assert.IsNull(resp); + } + + // parallel testing not supported in PCL #if !PORTABLE [Test] public async Task can_test_in_parallel() { diff --git a/src/Flurl.Http.Shared/Configuration/FlurlMessageHandler.cs b/src/Flurl.Http.Shared/Configuration/FlurlMessageHandler.cs index fc6ea403..4aacf7dc 100644 --- a/src/Flurl.Http.Shared/Configuration/FlurlMessageHandler.cs +++ b/src/Flurl.Http.Shared/Configuration/FlurlMessageHandler.cs @@ -14,6 +14,11 @@ public class FlurlMessageHandler : DelegatingHandler /// /// Initializes a new instance of the class. /// + public FlurlMessageHandler() { } + + /// + /// Initializes a new instance of the class with a specific inner handler. + /// /// The inner handler. public FlurlMessageHandler(HttpMessageHandler innerHandler) : base(innerHandler) { } diff --git a/src/Flurl.Http.Shared/FlurlClient.cs b/src/Flurl.Http.Shared/FlurlClient.cs index ae4e16c8..fffc2c07 100644 --- a/src/Flurl.Http.Shared/FlurlClient.cs +++ b/src/Flurl.Http.Shared/FlurlClient.cs @@ -17,7 +17,7 @@ public interface IFlurlClient : IDisposable { /// /// Creates a copy of this FlurlClient with a shared instance of HttpClient and HttpMessageHandler /// - FlurlClient Clone(); + IFlurlClient Clone(); /// /// Gets or sets the FlurlHttpSettings object used by this client. @@ -116,7 +116,7 @@ public FlurlClient(string url, bool autoDispose) : this(url) { /// /// Creates a copy of this FlurlClient with a shared instance of HttpClient and HttpMessageHandler /// - public FlurlClient Clone() { + public IFlurlClient Clone() { return new FlurlClient { _httpClient = _httpClient, _httpMessageHandler = _httpMessageHandler, diff --git a/src/Flurl.Http.Shared/Testing/HttpTest.cs b/src/Flurl.Http.Shared/Testing/HttpTest.cs index d5c51f61..28ffe8b0 100644 --- a/src/Flurl.Http.Shared/Testing/HttpTest.cs +++ b/src/Flurl.Http.Shared/Testing/HttpTest.cs @@ -19,11 +19,6 @@ public class HttpTest : IDisposable /// public static HttpTest Current => GetCurrentTest(); - private static readonly HttpResponseMessage EmptyResponse = new HttpResponseMessage { - StatusCode = HttpStatusCode.OK, - Content = new StringContent("") - }; - /// /// Initializes a new instance of the class. /// @@ -100,7 +95,10 @@ public HttpTest SimulateTimeout() { public Queue ResponseQueue { get; set; } internal HttpResponseMessage GetNextResponse() { - return ResponseQueue.Any() ? ResponseQueue.Dequeue() : EmptyResponse; + return ResponseQueue.Any() ? ResponseQueue.Dequeue() : new HttpResponseMessage { + StatusCode = HttpStatusCode.OK, + Content = new StringContent("") + }; } /// diff --git a/src/Flurl.Http/project.json b/src/Flurl.Http/project.json index 39d82ff4..c3443d60 100644 --- a/src/Flurl.Http/project.json +++ b/src/Flurl.Http/project.json @@ -1,6 +1,6 @@ { "title": "Flurl.Http", - "version": "1.1.2", + "version": "1.1.3", "dependencies": { "Flurl": "2.3.0",