Skip to content

Commit

Permalink
Fix #794 with passing unit test while preserving existing behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwasef1830 committed Jan 15, 2024
1 parent 6429dae commit dfc1506
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Flurl.Http/Configuration/DefaultJsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class DefaultJsonSerializer : ISerializer
/// Deserializes the specified stream to an object of type T.
/// </summary>
/// <param name="stream">The stream to deserialize.</param>
public T Deserialize<T>(Stream stream) => stream.Length == 0 ? default : JsonSerializer.Deserialize<T>(stream, _options);
public T Deserialize<T>(Stream stream) => stream.CanSeek && stream.Length == 0
? default
: JsonSerializer.Deserialize<T>(stream, _options);
}
}
13 changes: 13 additions & 0 deletions test/Flurl.Test/Http/RealHttpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ public class RealHttpTests
Assert.AreEqual(2, result.json["b"].GetInt32());
}

[Test]
[TestCase(HttpCompletionOption.ResponseHeadersRead)]
[TestCase(HttpCompletionOption.ResponseContentRead)]
public async Task can_get_json_with_http_completion_option_headers(HttpCompletionOption completionOption)
{
var result = await "https://httpbin.org"
.AppendPathSegment("gzip")
.WithHeader("Accept-encoding", "gzip")
.GetJsonAsync<Dictionary<string, object>>(completionOption);

Assert.AreEqual(true, ((JsonElement)result["gzipped"]).GetBoolean());
}

[Test]
public async Task can_get_stream() {
using (var stream = await "https://www.google.com".GetStreamAsync())
Expand Down

0 comments on commit dfc1506

Please sign in to comment.