Skip to content

Commit

Permalink
Merge pull request #191 from tmenier/dev
Browse files Browse the repository at this point in the history
Flurl.Http 1.1.3
  • Loading branch information
tmenier authored Jul 16, 2017
2 parents 7b0c2f3 + 0f1dca0 commit b2f56b6
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 36 deletions.
3 changes: 2 additions & 1 deletion Build/nuspec/Flurl.Http.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Flurl.Http</id>
<version>1.1.2</version>
<version>1.1.3</version>
<title>Flurl.Http</title>
<authors>Todd Menier</authors>
<projectUrl>http://tmenier.github.io/Flurl</projectUrl>
Expand All @@ -13,6 +13,7 @@
A fluent, portable, testable HTTP client library that extends Flurl's URL builder chain.
</description>
<releaseNotes>
1.1.3 - Minor fixes (github #175, #182, #186)
1.1.2 - Minor bug fixes (github #159 &amp; #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)
Expand Down
15 changes: 14 additions & 1 deletion Test/Flurl.Test.Shared/Http/GetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
34 changes: 10 additions & 24 deletions Test/Flurl.Test.Shared/Http/RealHttpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion Test/Flurl.Test.Shared/Http/TestingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions src/Flurl.Http.Shared/Configuration/FlurlMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public class FlurlMessageHandler : DelegatingHandler
/// <summary>
/// Initializes a new instance of the <see cref="FlurlMessageHandler"/> class.
/// </summary>
public FlurlMessageHandler() { }

/// <summary>
/// Initializes a new instance of the <see cref="FlurlMessageHandler"/> class with a specific inner handler.
/// </summary>
/// <param name="innerHandler">The inner handler.</param>
public FlurlMessageHandler(HttpMessageHandler innerHandler) : base(innerHandler) { }

Expand Down
4 changes: 2 additions & 2 deletions src/Flurl.Http.Shared/FlurlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface IFlurlClient : IDisposable {
/// <summary>
/// Creates a copy of this FlurlClient with a shared instance of HttpClient and HttpMessageHandler
/// </summary>
FlurlClient Clone();
IFlurlClient Clone();

/// <summary>
/// Gets or sets the FlurlHttpSettings object used by this client.
Expand Down Expand Up @@ -116,7 +116,7 @@ public FlurlClient(string url, bool autoDispose) : this(url) {
/// <summary>
/// Creates a copy of this FlurlClient with a shared instance of HttpClient and HttpMessageHandler
/// </summary>
public FlurlClient Clone() {
public IFlurlClient Clone() {
return new FlurlClient {
_httpClient = _httpClient,
_httpMessageHandler = _httpMessageHandler,
Expand Down
10 changes: 4 additions & 6 deletions src/Flurl.Http.Shared/Testing/HttpTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ public class HttpTest : IDisposable
/// </summary>
public static HttpTest Current => GetCurrentTest();

private static readonly HttpResponseMessage EmptyResponse = new HttpResponseMessage {
StatusCode = HttpStatusCode.OK,
Content = new StringContent("")
};

/// <summary>
/// Initializes a new instance of the <see cref="HttpTest"/> class.
/// </summary>
Expand Down Expand Up @@ -100,7 +95,10 @@ public HttpTest SimulateTimeout() {
public Queue<HttpResponseMessage> 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("")
};
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Flurl.Http/project.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "Flurl.Http",
"version": "1.1.2",
"version": "1.1.3",

"dependencies": {
"Flurl": "2.3.0",
Expand Down

0 comments on commit b2f56b6

Please sign in to comment.