Skip to content

Commit

Permalink
test failing due to httpbin bug, but this is a better way to test quo…
Browse files Browse the repository at this point in the history
…ted charset anyway
  • Loading branch information
tmenier committed Apr 9, 2017
1 parent df330a0 commit 11ac330
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
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
19 changes: 0 additions & 19 deletions Test/Flurl.Test.Shared/Http/RealHttpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,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

0 comments on commit 11ac330

Please sign in to comment.